Tuesday, October 4, 2011

Data retrieval with parameters on multiple models

I have several tables:

-Notes
-Users
-Favorites (favorite notes)
-Shares (shared notes)

Users hasMany Notes, Shares and Favorites are join tables between
Users and Notes.

I want to perform a Note search where I can filter by shared,
favorites and created by the user. Also I want to be able to search by
a parameter provided that can match either the title of the Note or
the User's username.

I know that for the Favorites and Shared I could just look matching by
id on those tables, but this won't return other related models of the
Notes which I want so I have to do the search on the Notes model to
get all the data I need.

I'm not sure how to proceed with this, I thought maybe using joins but
how can I specify an OR condition for the LIKEs as in User.username
LIKE $parameter OR Note.title LIKE $parameter? Because one condition
is specified in the join and the other in the find conditions for the
model.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: