2014-12-07 2 views
0

개발 시스템에 대신 라이브 서버 개체의 키, 그러나 모델을 반환하지만 그 중 하나는 ... 이상한 행동을한다elequent belongsTo를 내가 Laravel의 일부 모델이


이 좀 당황,

어떻게 든 내 개발 컴퓨터에서 내 프로덕션 서버에 다른 열 이름을 관리했습니다 ... 내 개발 컴퓨터에서 열의 이름은 creation_id입니다.하지만 내 프로덕션 컴퓨터에서는 생성이라고합니다 ...


I 편의

에 대한 조부모 내 개발 머신에있는 이벤트가 eventAttendees 이벤트에 속하는 창조와 hasMany의 eventAttendees에 속하고, 창조론자에 액세스 할 수 있습니다 많은 이벤트가있는 창조> 제목이 모든 것이 예상대로 작동하지만, 실제 서버에서는 이벤트 -> 생성에서 생성 대신 ID를받습니다.

공지 사항, 해당 EventAttende-> getEventCreationTitleAttribute는 'getCreationTitleAttribute'까지 작동합니다. 그 EventAttende-> 이벤트() 작동 ...

나는 오전 나는 데이터를 표시 frozennodes 관리자를 사용하고

// Filename: /app/models/Event.php 
<?php 
namespace XXX; 
class Event extends \Eloquent 
{ 
    protected $connection = 'legacy'; 

    public function creation() 
    { 
     return $this->belongsTo('XXX\Creation', 'creation_id'); 
    } 

    public function getCreationTitleAttribute() 
    { 
     $x = $this->creation; // I have also tried $this->creation()->first() which returns null on live server 

     // This should be the normal behaviour, the test shouldn't even be necessary 
     // And the test wasn't there before i uploaded to my live server 
     if (is_object($x)) 
      return $x->title; 

     // This is the flow I would expect, 
     // and the flow I get on my production machine... 
     return $x; 
    } 

    public function eventAttende() 
    { 
     return $this->hasMany('XXX\EventAttende'); 
    } 
} 

// Filename: /app/models/Creation.php 
<?php 
namespace XXX; 
class Creation extends \Eloquent 
{ 
    protected $connection = 'legacy'; 

    public function Creation() 
    { 
     $this->bgColor="FFFFFF"; 
     $this->textColor="000000"; 
     $this->linkColor="0000FF"; 
    } 

    public function events() 
    { 
     return $this->hasMany('XXX\Event'); 
    } 
} 

// Filename: /app/models/EventAttende.php 
<?php 
namespace XXX; 
class EventAttende extends \Eloquent 
{ 
    protected $connection = 'legacy'; 

    // this works 
    public function event() 
    { 
     return $this->belongsTo('XXX\Event', 'event'); 
    } 

    public function getEventCreationTitleAttribute() 
    { 
     return $this->event()->first()->creationTitle; 
    } 
} 

laravel 4.1

이 관련 코드를 사용하여 getCreationTitleAttribute은 frozenNodes 관리자에서 호출됩니다. (비즈니스 코드는 내가 아직 laravel에서 데이터를 사용하지 않는 오래된 기존 플랫폼입니다.)

속성을 사용하여 열 정의 부분은 이것이다 : 어떻게 든로 관리했다

/** 
* The display columns 
*/ 
'columns' => array(
    'id', 
    'creation_title' => array(
     'title' => 'Kreation', 
     //'name_field' => 'full_name', 
     //'type' => 'relationship', 
     //'relationship' => 'creation', 
    ), 
    'name' => array(
     'title' => 'Navn' 
    ), 

), 
+0

먼저'checked' 관계가'Model' 또는'null'을 반환하기 때문에 체크가 필요합니다. 그리고 아마 이것은 id이고, id를 반환하지 않는 것이 문제입니다. 후자는 관계와 테이블 열이 같은 이름을 가진 경우 ('id'는 반환하지 않지만 열 값은) 발생할 수 있습니다. –

+0

Hello Jarek, 이벤트 테이블에 creation이라는 열이 없으며 외래 키의 이름은 creation_id입니다. – buildcomplete

+0

실행 코드를 표시하십시오. –

답변

0

... 내 개발 컴퓨터에서 열이 creation_id라고 내 개발 시스템에

  • , 내 생산 시스템에
  • ,가 호출 될 때 생성을 ... 내 프로덕션 서버에 다른 콜 럼 이름이