Many of you will have played around with Doctrine behaviours before. I certainly did and one of my latest experiments is the LooseCoupling behaviour that allows you to work with loose relations without leading to high amounts of database queries.
Today I found a bug in this behaviour that was the result of my apparent misunderstanding.
In the template I defined a few delegate methods. One of which was querying the database.
To avoid doing the same query again I cached the result and the next time the method was called the cached result would be returned.
The mistake I made was to assume that there will be one templace instance per model instance.
But that’s not true as I discovered when the results I got returned from this delegate method where always the same.
In fact the setTableDefinition() method of any doctrine record will only be called once per model class not per model instance and the template will work as if static or a singleton.
This means that you can not store member attributes on the template like I did.
Have a look at my changeset to see what I mean.
There will be an even better way of course but this will do for now.
Behaviours · Doctrine · LooseCoupling · symfony
-
wissl
<< So you want a clean and easy way to manage dynamic doctrine relations in your symfony forms?

