Extend the with() method in CActiveRecord

Maybe there exists some other ways to do this. But I can't find it. ^^

First, I could fetch a shop object with its customers and shop_products as following code:

Quote

$shops->with(array('customers', 'shop_products'))->findByPk(10);

I know I could put some options as mentioned in document( http://www.yiiframew…de/database.arr ), but how could modify those options in run time?

And, how about using similar syntax like this:

$shops->with(array(


    'customers' => array(


        'select' => array(...),


        'condition' => array(...),


        'order' => array(...),


        'joinType' => array(...),


        'with' => array(...),


    ),


	'shop_products'


))->findByPk(10);

Just like containable behavior in cakephp. ;)

Right now with() is a bit limited because it can only allow static relations as declared in relations(). The underlying RAR can however support dynamic queries like you want. The problem lies in how to specify the with() parameters, because right now you can do the following deeply nested query:



$shops->with(array('customers'=>array('profile', 'orders'), 'shop_products'))->findByPk(10);


which is very similar in structure to your proposed parameter.

Maybe set the option key as reserved words and process before model bindings? Or maybe there could have one method to modify each relation on run time and restored after the query completed.

I know relying on active records not making sense. But it make life easier. :)

Perhaps using this syntax? Anyway, could you please create a ticket for this? Thanks.



$shops->with(array(


	'customers'=>array(


		'select'=>...,


		'order'=>...,


	),


	'customers.profile'=>array(


		'select'=>...,


		'order'=>...,


	),


	'customers.orders'=>array(


		'select'=>...,


		'order'=>...,


	),


	'shop_products'


))->findByPk(10);


Done.

http://code.google.c…s/detail?id=103

;)