Get the last insert id with doctrine 2?

后端 未结 7 2300
礼貌的吻别
礼貌的吻别 2020-12-08 03:26

How can I get the last insert id with doctrine 2 ORM? I didn\'t find this in the documentation of doctrine, is this even possible?

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 04:06

    Calling flush() can potentially add lots of new entities, so there isnt really the notion of "lastInsertId". However Doctrine will populate the identity fields whenever one is generated, so accessing the id field after calling flush will always contain the ID of a newly "persisted" entity.

提交回复
热议问题