>From database normality PoV, you should stick with your current structure
(approach 2). Complexity of SELECT query should belong to CakePHP engine,
not yours.

If you have defined the Model Association correctly, CakePHP will also
retrieve related tables, so you shouldn't worry about how to query.

>From what I understand, you will have the following associations:

User hasOne Profile (and Profile belongsTo User)
User hasMany Friend (and Friend belongsTo User)

If you queried (findAll) a Profile, CakePHP will also fetch related User,
Friends, and Friends' User. CakePHP have a recursive limit of 3, that means
you can only get 3 associated tables from the current one. This is good
enough for your problem.

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of Mandy
Sent: 19 Nopember 2006 19:24
To: Cake PHP
Subject: Querying Question


Hi,

This might not necessarily related to cake, but I would like to know
what's the best way to do this.

I have a users table (that has user_id, first_name, last_name...etc)
And a profile table (profile_id, user_id, country....)
And a friends table which has (friend_id, user_id profile_id)

Now on the profile page, for that particular profile, I query friends
table to get the user_id's of all the friends and display their photos,
because all photos are user_id.jpg, but now I want to display the
user's first name as well but that is in the user's table.

I have 2 approaches -

1) Put user_name also in the friends table
2) Loop through all friends and for every entry go to the user table to
get the user first name

What do you guys suggest?

2nd one will have lots of select queries whereas first one would just
duplicate data?

Thanks in advance,
Mandy.




--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to