Wednesday, October 5, 2011

Re: Data retrieval with parameters on multiple models

I managed to do what I wanted but I ran into another problem. I was
able to do my join properly just using the joins option in the find
method, but to make it work I had to unbind the User model, because it
would give an SQL error because the join statement it generate was
wrongfully located in my query for it to work, so I unbound the model
and added the join clause myself. The problem is that I actually need
the user info and its no coming with the join statement.

On Oct 4, 5:02 pm, 8vius <lmd...@gmail.com> wrote:
> 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: