2014-02-05 3 views
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') 

    ); 

사용자 위치가 아닌 항상 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 

나는 왜 이것이 이제는 더 이상 아무것도 반환하지 않는다는 것을 전혀 모른다. ferent 신택스.

나는 Laravel 방식으로 돌아갈 수는 있지만 Ardent 's 구문이 더 마음에 든다.

답변

0

열 이름/관계 충돌의 간단한 경우.

관련 문제