Kohana ORM 别名和“尝试获取非对象的属性”
我在数据库中有以下表格:
- 团队:
- ID
- 姓名
- 匹配:
- ID
- team1_id
- team2_id
我在我的 ORM 模型中定义了以下="http://kohanaphp.com/" rel="nofollow noreferrer">Kohana v2.3.4 应用程序:
class Match_Model extends ORM {
protected $belongs_to = array('team1_id' => 'team', 'team2_id' => 'team');
}
class Team_Model extends ORM {
protected $has_many = array('matches');
}
控制器中的以下代码:
$match = ORM::factory('match',1);
echo $match->team1_id->name; /* <-- */
在标有 /* 的链接上引发以下错误<--- */
:
尝试获取非对象的属性
框架正在生成外键的值,而不是应有的对 Match_Model 实例的引用(给出has_many 和belongs_to 属性声明)。
我遗漏了什么吗?
注意:为了以防万一,我添加了不规则复数 'match' =>; application/config/inflector.php 中的“匹配”
I have the following tables in the database:
- teams:
- id
- name
- matches:
- id
- team1_id
- team2_id
I've defined the following ORM models in my Kohana v2.3.4 application:
class Match_Model extends ORM {
protected $belongs_to = array('team1_id' => 'team', 'team2_id' => 'team');
}
class Team_Model extends ORM {
protected $has_many = array('matches');
}
The following code in a controller:
$match = ORM::factory('match',1);
echo $match->team1_id->name; /* <-- */
Is throwing the following error on the linke marked with /* <--- */
:
Trying to get property of non-object
The framework is yielding the value of the foreign key instead of a reference to a Match_Model instance as it should (giving the has_many and belongs_to properties stated).
Am I missing something?
Note: Just in case, I've added the irregular plural 'match' => 'matches'
in application/config/inflector.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决! Kohana 社区给了我答案 :
$belongs_to 属性的正确值是:
文档 指出:
看来我错过了那条线,:)
SOLVED! The Kohana community gave me the answer:
The correct value for the $belongs_to property is:
The documentation states it:
It seems that I've missed that line, :)