elequent 属于 To 返回 key 而不是活动服务器上的对象,而是返回开发计算机上的模型



我在拉拉维尔有一些模型,但其中一个表现得很奇怪......


这有点尴尬,

我以某种方式设法在我的生产服务器上与我的开发机器有不同的列名称......在我的开发计算机上,该列称为creation_id,但在我的生产计算机上,该列称为创建...


我有一个有很多事件的创作该事件属于创建,并且有许多活动参与者活动参与者属于活动,为了方便起见,可以访问创建>标题,即祖父

级在我的

开发机器上,一切都按我预期工作,但是在我的实时服务器上,我获得了 id 而不是从事件>创建中创建......

请注意,EventAttende->

getEventCreationTitleAttribute 工作直到"getCreationTitleAttribute",这意味着 EventAttende->event(( 工作...

我正在使用拉拉维尔 4.1

这是相关的代码,getCreationTitleAttribute 是从 frozenNodes 管理员调用

// Filename: /app/models/Event.php
<?php
namespace XXX;
class Event extends Eloquent 
{
    protected $connection = 'legacy';
    public function creation()
    {
        return $this->belongsTo('XXXCreation', '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('XXXEventAttende');
    }
}
// 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('XXXEvent');
    }
}
// Filename: /app/models/EventAttende.php
<?php
namespace XXX;
class EventAttende extends Eloquent 
{
    protected $connection = 'legacy';
    // this works
    public function event()
    {
        return $this->belongsTo('XXXEvent', 'event');
    }
    public function getEventCreationTitleAttribute()
    {
        return $this->event()->first()->creationTitle;
    }
}

我正在使用冻结节点管理器来显示数据。(业务代码是一个较旧的遗留平台,所以我还没有使用来自 laravel 的数据。

使用该属性的列定义部分如下所示:

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

我以某种方式设法在我的生产服务器上与我的开发机器有不同的列名称......

  • 在我的开发计算机上,该列称为creation_id,
  • 在我的生产机器上,它被称为创建...

最新更新