associations - CakePHP 1.3.4 $belongsTo problem incase of Relationship table -


I have a table named user_relationship, which has two foreign keys that are a map to return to the user table that they are friends.

  create tab 'user-relationship` (`id`inte (11) unsigned non-auto_ignment,` status' varchar (255) default 'pending', 'time' data time default noise, Key `fk_user_relationships_users2` (` friend_id`)); `user_id` (11) unsigned,` `friend_id` int '' (11) unsigned null, primary key (` id`), key `fk_user_relationships_users1` (` user_id`) = InnoDB default charset = latin1 AUTO_INCREMENT = 1;  

When I try to bake it, then naturally it does not seem that friend_id has to refer to the user module. I want to manually edit the code but there are some problems in the o that are related to

  var $ edit = array ('user' = & gt; array ('className' = 'User', 'foreign_key' = & gt; 'user_id', 'conditions' => "',' fields '=>,' order '=>),' Friends' = & gt; array ('classname' = & gt; 'friend', 'foreigner' => 'friend_id', 'conditions' =>' ',' fields' => I want to see user_id in the Users table in this part of the code  
  'Friends' = & Gt; array ('classname' = & gt; 'friend', 'foreign key' = & gt; friend_id ',' conditions '=> gt;' ',' field '=>,' 'order' = & Gt; '')  

I tried to do this .. Do I need to change something else?

  'friend' = & Array ('classname' = & gt; 'friend', 'foreigner' = & gt; 'user_id', 'conditions' => "', 'fields' =>",' order '= & Gt; '')  

How about it?

UserUser class => User class = "" user = "" class = " ), 'Friends' = & gt; Array (' className '=> User', 'Foreign key' => 'friend_id')); } Class user {var $ is and Belongtomania = array ('Friends' = & gt; array ('classname' = & gt; 'user', 'jointable' = & gt; 'user-reliance', 'foreigner' = & gt; 'User_ID', 'Association Arizynki' = & gt; friend_id ',' with '= & gt;' UserRelationship ')); }

Organizations can be viewed from different points of view:

  Users & lt; - relationship - & gt; User | | | I have a lot. Relationships & lt; - The user (user_id) has. User (friend_id) - & gt; Relationships | | HABTM HABT user & lt; ---------------------- & gt; User  

Your "physical" layout, i.e. database schema, is the user - & gt; Relationships - & gt; User . Your real desired relationship is a user - & gt; User However, the relationship translates technically into the user and the BellongsTomNi user association (which is also called many-to-many). Because it uses three models, it can be broken in many different associations:

  • Users have many relationships / relatives user
  • Relative relationship is the user / user has many relationships

You do not have required AndBelongsToMany Association, but this is exactly what you want. You do not really need a relation model because it is only a helpful model to connect two users, but if you want to specify do your associations, then it has two related associations . / P>


Comments