Thanks for your answers guys... Baz,
The solution you are giving to me is simply great! But I don´t understand one thing... Can I make this associations in Cake 1.2 if I don´t have the "Friends" model? Or sholud I use the plain SQL? Zen, What do you want to say with "Sometimes it's simply better to make the querys and merge the info. And a lot faster too." I´m not following u here... Martin Bavio On Nov 13, 6:55 am, "Ricardo Valfreixo" <[EMAIL PROTECTED]> wrote: > Hello people. > > I agree with Baz. It's simply a question of Data Design. > > You should create a relationship table where you can map all relations. You > could even add a new field and make diferent type os relationship (like > buddies, family, coworkers, something like that). Sometimes it's simply > better to make the querys and merge the info. And a lot faster too. > > Just my two cents :) > > Zen > > On Nov 13, 2007 6:00 AM, Baz <[EMAIL PROTECTED]> wrote: > > > > > Yes, > > > It is a database design question. > > > No you can't relate them in the users table because a user can have more > > than one friend. I think this is what they are suggesting: > > > Table: friends_users > > id - int > > user_id - int > > friend_id - int > > > In this case, I don't think you would use a *friends* table. When looking > > up user with id = 1, you'd have to query his friends separately. Without > > giving it too much thought, there would be two queries for his friends: > > > select friend_id from user_friend where user_id = 1 > > and > > select user_id from user_friend where friend_id = 1 > > > Off the top of my head, I would perform these two searches in my > > controller and merge both results into an array. But that's just my lazy > > code talking. Keep in mind, I'm not too good with the HABTM association. > > > Good luck > > -- > > Baz L > > Web Development 2.0: Web Design, CakePHP, Javascript > >http://www.WebDevelopment2.com/ > > > On Nov 12, 2007 9:42 PM, mbavio < [EMAIL PROTECTED]> wrote: > > > > Baz, > > > > Thanks for your quickly answer. By the way, I´ve read your blog. Great > > > articles! > > > > Going back to my problem... > > > > Beyond making Bob and Tim friends, what I wanna know is what to put in > > > the Friends table... The IDs of the Users again? Isnt that a useless > > > repetition? Cant I simply relate the Users in the same table? I think > > > this issue is beyond I´m using Cake, Ruby or Assembler... It´s a > > > question of database design, and I´m simply lost... Any brillant idea? > > > > Martin Bavio > > > > On Nov 13, 12:24 am, Baz < [EMAIL PROTECTED]> wrote: > > > > Hmmmph, > > > > > I was wondering that myself. The easy way is to do what's suggested > > > above, > > > > but duplicate and entry for each relationship: > > > > > Eg. When Bob becomes Tim's friend (in the before/afterSave) force and > > > entry > > > > that makes Tim Bob's friend. > > > > > Of you could have one relationship and simply check the "other > > > direction" > > > > logically in your controllers. But I don't think there are any easy > > > Cake > > > > answers. > > > > -- > > > > Baz L > > > > Web Development 2.0: Web Design, CakePHP, > > > Javascripthttp://www.WebDevelopment2.com/ > > > > > On Nov 12, 2007 9:14 PM, mbavio < [EMAIL PROTECTED]> wrote: > > > > > > Christopher: > > > > > > I understand the basics behind Cake´s HATBM, but I do not understand > > > > > how to implement here... You have to notice that "Friends" are also > > > > > "Users", so I dont know how to build the tables. Should I put the > > > same > > > > > id in both tables? If not, what is the primary key in the "Friends" > > > > > table? > > > > > This case is typical in a CMS, where you want to let the user make > > > > > "friends" in the community. Anybody who has solved this particular > > > > > problem? > > > > > > Thanks. > > > > > > On Nov 12, 7:43 pm, "Christopher E. Franklin, Sr." > > > > > <[EMAIL PROTECTED]> wrote: > > > > > > Yes, this is a HABTM relationship both ways between friends and > > > > > > users. Define the $hasAndBelongsToMany variable at the top of > > > each > > > > > > model appropriately and then make an extra db table named: > > > > > > friends_users and within the table, you will have two fields, > > > > > > friend_id and user_id. > > > > > > > After you have a few users and friends, if you want to see a > > > user's > > > > > > friend of a friend of a friend, you use, the recursive option for > > > the > > > > > > model: > > > > > > eg- > > > > > > $this->User->recursive = 1; > > > > > > > The higher you go, the more levels deep will get returned > > > > > > > On Nov 12, 2:20 pm, mbavio <[EMAIL PROTECTED]> wrote: > > > > > > > > I have a 'User' model, and I want that my Users can have > > > Friends, > > > > > > > being Friends other Users. Is this a "self HATBM"? How can I > > > solve > > > > > > > this problem? > > > > > > > > Thanks. > > -- > ----------------- ----------------- --------------- > name: Ricardo Valfreixo > e-mail: [EMAIL PROTECTED] > msn: [EMAIL PROTECTED] > ----------------- ----------------- --------------- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
