[Phpwm] symfony related records

Darren Beale public.darren.beale at siftware.co.uk
Fri Feb 8 18:43:05 GMT 2008


Hi,

> Anyone else using the Symfony framework?

Yes
 
> 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

This is as much propel as Symfony.

In a related Peer (do stuff with database) class, let's say
lib/model/ItemPeer.php add a new method:

public static function getOrderItemsByUserId($id)
{
	$c = new Criteria();

	$c->add(UserPeer::ID, $id);

	$c->addJoin(UserPeer::ID, OrderPeer::USER_ID);
	$c->addJoin(OrderPeer::ID, parent::ORDER_ID);

	return parent::doSelect($c);
}

Within your action you can then call

$orderItems = ItemPeer::getOrderItemsByUserId($id);

If you're in _dev mode you should be able to see that this has given you a
simple 3 table join where user.id = $id.

hth, I've not checked this through but the jist is right

Regards

--
Darren Beale

Siftware
1 North Works
London Lane
Upton-upon-Severn
WR8 0HH

t: 01684 59 49 59
m: 07711 716 197

w: http://siftware.co.uk 
b: http://bealers.com



No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.516 / Virus Database: 269.19.21/1265 - Release Date: 07/02/2008
11:17
 




More information about the Phpwm mailing list