【问题标题】:Laravel 4 - Ardent - Unable to use $relationsDataLaravel 4 - Ardent - 无法使用 $relationsData
【发布时间】:2014-02-05 16:37:03
【问题描述】:

我已经以传统方式定义了我的模型关系,并且一直运行良好。然而,我开始使用 Ardent 来简化验证,并注意到它具有定义 Eloquent 关系的有用功能。

https://github.com/laravelbook/ardent#relations

为了把它放在上下文中,我有一个用户模型,它属于一个位置(在本例中是地理)。

以前,我会使用:

public function location(){
    return $this->belongsTo('Location', 'location');
}

我没有任何问题。改用 Ardent 的做法产生了:

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 的语法。

【问题讨论】:

    标签: laravel ardent


    【解决方案1】:

    列名/关系冲突的简单案例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 2014-05-08
      • 2013-12-31
      • 2013-08-03
      • 1970-01-01
      • 2014-01-27
      • 2015-02-13
      相关资源
      最近更新 更多