与关注者|朋友用户的自我参照关系 [英] Self referencing relation with followers|friends users

查看:82
本文介绍了与关注者|朋友用户的自我参照关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了建立用户之间的关系,创建了一个看起来像表的表.

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`)
 );

您可能知道-字段fromtousers表中user_id的键.

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

我正在使用Kohana 3.09及其默认模块Auth.

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

问题是...

*如何通过具有(默认)Model_User类的用户关系实现ORM功能?*

*How to make ORM functionality around relations of users with (default) Model_User class?*

是否有任何针头可以用来创建其他类,或者我对one_to_many特洛伊特和many_to_many特洛伊特的关系有一些错误,导致它无法正常工作. 请帮忙. 我最诚挚的问候.

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.

这篇关于与关注者|朋友用户的自我参照关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆