Hey all I'm hoping someone has enough experience with Cake PHP to make this work.
I'm working on something that at the moment could affectionately be called a twitter clone. Essentially I have a set up like this.
Users have many friends. This is a many to many relationship to the user table. It is stored in a link tabled called friends_users with columns user_id, friend_id. Users is a table with column user_id.
Then i have a table called tips which associates to a user. A user can have many tips.
I want to figure out a way to do a find on the Tip model that returns all tips owned by the userid i pass in as well as any tips owned by any friends of that user.
This SQL query works perfectly -
SELECT *
FROM `tips`
JOIN users ON users.id = tips.user_id
JOIN friends_users ON tips.user_id = friends_users.friend_id
WHERE (friends_users.user_id =2 or tips.user_id=2)
LIMIT 0 , 30
That returns user#2s Tips as well as the tips of anyone who is a friend of User 2.
Now how can i do the same thing using $this->Tip->findxxxxx(user_id)
I know i can use Tip->query if need be but i'm trying to learn the hard way.