为了使用户之间的关系创建了一个看起来像的表。

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

您可能知道 - 字段 fromto 是一个钥匙 user_idusers 桌子。

我使用的是Kohana 3.09及其默认模块auth。

问题是...

*如何使用户与(默认)model_user类的关系围绕ORM功能?

是否有任何针头创建其他课程的针头,或者我与关系one_to_many trouth和Many_to_many trouth犯了一些错误,因为它不起作用。请帮忙。我最诚挚的问候。

有帮助吗?

解决方案

您应该查看文档的这一部分:

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

您需要在您的用户课内类似的东西

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

使用这些选项 在源代码中的此部分.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top