I think that's maybe a db design issue more than a cake one and it really depends on what you want to accomplish with your data. I'd recommend doing some reading on the concepts of db normalization and data models:
http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html http://www.tonymarston.net/php-mysql/database-design.html http://www.utexas.edu/its/windows/database/datamodeling/index.html On May 17, 2:47 pm, Victor <[EMAIL PROTECTED]> wrote: > I am trying to define the right model and relationship for User and > Friend. Here are my tables > > CREATE TABLE users { > id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, > name VARCHAR (20) > > } > > CREATE TABLE friends { > user_id INT UNSIGNED, > friend_id INT UNSIGNED > PRIMARY KEY(user_id, friend_id) > > } > > The next thing is to define relationship. I use bake command to create > relationship. User hasAndBelongsToMany Friend. > > So my User model includes this: > > var $hasAndBelongsToMany = array( > 'Friend' => array('className' => 'Friend', > 'joinTable' => 'friends', > 'foreignKey' => 'user_id', > 'associationForeignKey' => > 'friend_id', > 'conditions' => '', > 'fields' => '', > 'order' => '', > 'limit' => '', > 'offset' => '', > 'unique' => '', > 'finderQuery' => '', > 'deleteQuery' => '', > 'insertQuery' => ''), > ); > > The question is that does the Friend model need to include Friend > hasAndBelongsMany User relationship? If it does what should it look > like? > > Should Friend model just simply have Friend belongs User relationship? > > Is my friends table setup right? Is there better way? > > Will this setup not allow cases where user A has B as friend but B > does not have A as friend? > > Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
