0
我有我的模型關係定義傳統的方式,它一直工作正常。不過,我開始使用Ardent來簡化驗證,並注意到它具有定義Eloquent關係的有用功能。
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')
);
它總是返回空而不是用戶的位置。
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
我不知道爲什麼現在不再返回任何東西,因爲它是相同的只是dif不同的語法。
我可以回到Laravel的方式,但我更喜歡Ardent的語法。