[Phpwm] symfony related records

Andy Cowan andyc at waverider.net.uk
Fri Feb 8 18:19:48 GMT 2008


Hi All,

Anyone else using the symfony framework?

If so, how do you deal with related records that are several tables away in the model? For example, say I have the following structure:

Users-->Orders-->Items

And I want to get all the items that a user has ordered? The obvious first attempt is to use

$this->user->getOrders()->getItems();

But after thinking about it for 2 seconds, it’s clear this won’t work – getOrders() returns an array of order objects.

I can think of several ways of doing it – all of them seem wrong, and I can’t help thinking that there’s a right way that’s better than the way I’m going.

Use $this->getOrders() and foreach over the results doing getItems()? Very inefficient.

Use raw sql in the actions.class.php? Again, seems like a dirty hack.

I’ve resorted to adding a getItems() method of my own to the  user class, but again this just seems to be bypassing the ORM.

Any ideas?

A.



No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.19.21/1263 - Release Date: 06/02/2008 20:14


Wave Rider Internet is a trading style of OpenSense Ltd.
Registered in England and Wales No 04999653



More information about the Phpwm mailing list