Kohana 3.2 ORM 定义由两列组成的外键
我正在 Kohana 框架上构建一个应用程序。对于内容管理,我将使用 Joomla 框架,因此我们的撰稿人可以在他们熟悉的 UI 中轻松添加和编辑内容。
我定义了一篇文章可以所属的几个类别。例如博客 (catid = 1
) 和产品 (catid = 2
)。通过 joomla 内容表中的 xreference
列,用户必须将文章分配给所选类别中的特定 ID(因为 Model_Blog
可以包含 id = 1< /code> 以及
Model_Product
都可以)。
因此,Joomla 中的每篇文章都由 catid
和 xreference
的独特组合组成。现在我想将此一对一关系绑定到我的 Kohana ORM 模型(例如 Model_Blog
),但标准 Kohana ORM $_has_one
属性仅支持由以下组成的外键一列而不是多个 AFAIK。
我尝试了以下方法,当然,这是行不通的:
protected $_has_one = array(
'content' => array('model' => 'cms_content', 'foreign_key' => 'xreference', 'catid' => '1')
);
任何人都可以建议我如何正确绑定这种关系吗?
I am building an application on the Kohana framework. For content management, I will be using the Joomla framework, so our copywriters can easily add and edit content in a to them familiar UI.
I have defined several categories to which an article can belong to. E.g. blog (catid = 1
) and product (catid = 2
). With the xreference
column in the joomla content table, the user must assign the article to a specific id in the category selected (because Model_Blog
can contain id = 1
, as well as Model_Product
can).
So every article in Joomla consists of a unique combination of catid
and xreference
. Now I want to bind this one-to-one relation to my Kohana ORM models (e.g. Model_Blog
), but the standard Kohana ORM $_has_one
property only supports foreign keys consisting of one column instead of multiple AFAIK.
I tried the following, which, of course, doesn't work:
protected $_has_one = array(
'content' => array('model' => 'cms_content', 'foreign_key' => 'xreference', 'catid' => '1')
);
Can anyone advise me on how to bind this relationship correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在查找源代码后,我发现 Kohana ORM 不支持我描述的功能,我必须扩展 ORM 模块(这是因为 Kohana 的性质,小菜一碟:)),以实现多种功能FK 列。
现在,我可以使用以下语法定义一个列数组,这些列构成关系中的外键:
请注意,我的解决方案仅适用于 1 对 1 关系,因为在我的情况下,不需要为 1- 实现它to-many,尽管我怀疑这需要类似的修改
After a lookup in the source code, I found out that Kohana ORM doesn't support the feature I described and I had to extend the ORM module (which is because of Kohana's nature, a piece of cake :)), to implement multi-column FK's.
Now I can define an array of columns which form the foreign key in the relationship with the following syntax:
Please note that my solution only applies to a 1-to-1 relationship, because in my case there's no need to implement it for 1-to-many, although I suspect this would require a similar modification