test.ical.ly | getting the web by the balls

Oct/10

13

A word about Doctrine Record Behaviours

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.

· · ·



  • wissl

    We ran into that problem some time ago, too. Our current workaround is exactly what you did. So I am looking forward to your more elegant solution ;)

    In my company we have a behavior quite similar to yours (“loose coupling”) and what we added to it is the possibilty to create custom queries for each object type to be able to add some joins or additional where-clauses. You could do that for example by using the EventDispatcher approach.

  • http://test.ical.ly Christian

    @wissl sounds interesting. care to share an example?

<<

>>

Theme Design by devolux.nh2.me