Thursday, April 1, 2010

Can I filter on models deep in a 'contains' ?

I'm trying to use a combination of the 'contains' behaviour,
pagination and filters to generate data to show in a table. The
application is an auction app that has auctions, which have bids on
them and each bid is also associated with a user.

Auction
Item
Attribute
LatestBid
User


In my controller I have pagination defined thus...

var $paginate = array(
'Auction' => array(
'limit' => 50,
'fields' =>
array('id','start_time','end_time','active','start_price','item_id','created'),
'contain' => array(
'Item' => array(
'fields' => array('id','sku','title','created'),
'ItemAttribute' => array('fields' =>
array('name','value','item_id'))
),
'LatestBid' => array(
'fields' =>
array('id','auction_id','bid_amount','created','user_id'),
'User' => array('fields' => 'username')
)
),
'order' => array('Auction.end_time' => 'desc')
));

This works a treat and I get back the data exactly as I want it. The
next step is I'm trying to add a search feature to the table so that a
user can type in any value in the table and have it search those
fields. One of the fields I want to search on is the username that
belongs to the User model which is associated with the LatestBid but
I'm not sure if I can do this. I've seen examples showing filtering 1
level down, i.e. I'd be able to filter on LatestBid.bid_amount, but
not seen 2 levels down and I'm not sure this is even possible because
the user information is retrieved in a separate SQL request by the
looks of things.

Any ideas?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

To unsubscribe, reply using "remove me" as the subject.

No comments: