为了建立用户之间的关系,创建了一个如下所示的表。
sql
CREATE TABLE `friends`(
`from` INT NOT NULL,
`to` INT NOT NULL,
UNIQUE INDEX(`from`, `to`)
);
你可能知道 - 领域from
and to
是一个键user_id
from users
table.
我正在使用 Kohana 3.09 及其默认模块 Auth。
问题是...
*如何使用(默认)Model_User 类围绕用户关系创建 ORM 功能?*
是否需要创建额外的类,或者我在 one_to_many trouth 和 Many_to_many trouth 关系上犯了一些错误,因为它不起作用。
请帮忙。
我最诚挚的问候。
您应该查看文档的这一部分:
http://kohanaframework.org/guide/orm/relationships#hasmany http://kohanaframework.org/guide/orm/relationships#hasmany
你的用户类中需要这样的东西
protected $_has_many = array(
'friends' => array(
'model' => 'user',
'through' => 'friends',
'far_key' => 'from',
'foreign_key' => 'to',
)
);
使用这些选项在源代码的这一部分 https://github.com/kohana/orm/blob/7edd666dc248c9521aff9730d2883a0f89347418/classes/kohana/orm.php#L349.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)