Limiting/Specifying Associated Queries
Hello,
Basically I'm wondering if there's an easy way to do 2 things. I have a two tables, submissions and users joined by a HABTM relationship via submissions_users.
EDIT: Figured this part out
___________________________
Now say, for efficiency, when I'm getting a large list of submissions and their associated users, is there any way for me to specify which fields in the users table to fetch? By default when I do $this->Submission->find('all') it'll grab ALL the fields in the Users table (a lot) when all I really need are name and id. Is there an easy way to specify this or would I have to go through the submissions results 1 by 1 on a lower recursive value and fetch the associated users 1 by 1?
---------------------------
STILL wondering about this ->
On the same note, can I specify fields in a related table as a condition for a query? For example, I have a field in submissions called subtype_id that refers to a table called subtypes (via hasOne). Would it be possible when I do $this->Submission->find() for me to specify, say Subtype.name = 'Audio' or something? It seems that if I have to hardcode in the id's of various types of submissions so that I can run the query more easily kind of defeats the purpose of associating a table with it.
Thanks!
Asked by revenantprime, on 28/2/10
1 Answer
Take a look at the Containable behavior, pretty sure it will do what you want.
It can do the subqueries and limit the fields brought in by associations. To limit your model fields use the 'fields' parameter.
http://book.cakephp.org/view/474/Containable
Answered by davidwuon 8/3/10
Your Answer
You can use Creole Wiki Syntax to format your text.
Tagged with
Rating
0
Viewed
173 times
Last Activity
on 8/3/10