How to check if entity changed in Doctrine 2?

前端 未结 9 744
盖世英雄少女心
盖世英雄少女心 2020-12-23 20:53

I need to check if a persisted entity has changed and needs to be updated on the database. What I made (and did not work) was the following:

$product = $enti         


        
9条回答
  •  臣服心动
    2020-12-23 21:13

    I agree with @Andrew Atkinson when he said:

    You may also want to look at the PreUpdate event, if you need access to entity fields with their old and new values.

    But I disagree with the example he proposed, from my experience, there is a better way to check if something changed or not.

    getEntityChangeSet())) {
                // fill this how you see fit
            }
        }
    }
    

    This way the if will only be triggered if there is really some field that changed or not.

    As to how to do it if this or that field was changed, then yeah, I recommend his solution.

提交回复
热议问题