开发者

Self referencing relation with followers|friends users

开发者 https://www.devze.com 2023-02-04 10:24 出处:网络
To make relationship between users was created a table that looks like. sql CREATE TABLE `friends`( `from` INT NOT NULL,

To make relationship between users was created a table that looks like.

sql
CREATE TABLE `friends`(
 `from` INT NOT NULL,
 `to` INT NOT NULL,
 UNIQUE INDEX(`from`, `to`)
 );

As you may know - field from and to is a keys of user_id from users table.

I'm using Kohana 3.09 with its default module Auth.

Question is...

*How to make ORM functionality around relations 开发者_C百科of users with (default) Model_User class?*

Is there any needle to create additional class or perhaps i had some mistakes with relations one_to_many trouth and many_to_many trouth cause it did not work. Please help. My best regards.


You should check out this section of the documentation:

http://kohanaframework.org/guide/orm/relationships#hasmany

You'll need something like this within your user class

protected $_has_many = array(
    'friends' => array(
        'model' => 'user',
        'through' => 'friends',
        'far_key' => 'from',
        'foreign_key' => 'to',
    )
);

These options are used at this part in the source code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号