我已经用传统的方式定义了我的模特关系,它一直运作得很好。然而,我开始使用Ardent来简化验证,并注意到它有一个有用的特性来定义雄辩的关系。
https://github.com/laravelbook/ardent#relations
要将其放到上下文中,我有一个用户模型,即belongs_to是一个位置(在这个实例中是地理位置)。
在此之前,我会用:
public function location(){
return $this->belongsTo('Location', 'location');
}我一点问题都没有。转变成热烈的做法已经产生了:
protected static $relationsData = array(
'location' => array(self::BELONGS_TO, 'Location', 'foreignKey' => 'location')
);它总是返回null,而不是用户位置。
User.php
use LaravelBook\Ardent\Ardent;
class User extends Ardent implements UserInterface, RemindableInterface {
protected static $table = 'agents';
protected static $relationsData = array(
'location' => array(self::BELONGS_TO, 'Location', 'foreignKey' => 'location')
);
}数据库代理id: int(11) PK位置: int(11) FK(locations.id)
*locations*
id: int(11) PK
longtext: text我不知道为什么现在它不再返回任何东西了,因为它是相同的,只是不同的语法。
我可以回到Laravel的方法,但我更喜欢Ardent的语法。
发布于 2014-02-05 17:15:58
列名/关系冲突的简单情况。
https://stackoverflow.com/questions/21583057
复制相似问题