正如你在下图中所看到的,我的购物单和购物单工艺路线步骤计划之间的早期关系并不是必须的。

我不知道我到底做错了什么,所以我希望有人能帮助我。在下面的代码中,为了使代码更易读,我在代码中去掉了一些字段。
class shoporder extends Model
{
protected $primaryKey = 'ID';
protected $fillable = [
'CADDrawingURL',
'ID',
'Costcenter',
'CostcenterDescription',
'Costunit',
'CostunitDescription',
'Created',
'Creator',
'CreatorFullName',
'Description',
'ShopOrderParent',
'ShopOrderParentNumber',
'ShopOrderRoutingStepPlanCount',
'Status',
'SubShopOrderCount',
];
public function shopOrderRoutingStepPlans() {
return $this->hasMany('App\shopOrderRoutingStepPlan', 'ShopOrder', 'ID');
}
}
class ShopOrderRoutingStepPlan extends Model
{
protected $primaryKey = 'ID';
public $table = "shoporderroutingstepplans";
protected $fillable = [
'Account',
'ID',
'AccountName',
'AccountNumber',
'AttendedPercentage',
'Backflush',
'Created',
'Creator',
'CreatorFullName',
'Description',
'ShopOrder',
];
public function shopOrder() {
return $this->belongsTo('App\shopOrder', 'ShopOrder', 'ID');
}
}这是我正在执行的代码,用于在控制器中获取1个商店订单之间的关系。
$orders = shopOrder::find('0600959e-6b92-4135-8ea8-1fa2fd92a916')->shopOrderRoutingStepPlans()->get();在商店订单迁移中,我定义了主键:
$table->string('ID')->unique();
$table->primary('ID');在shoporderroutingstepplans迁移中,我按如下方式定义了外键。
$table->string('ID')->unique();
$table->primary('ID');
$table->foreign('ShopOrder')
->references('ID')
->on('shoporders');发布于 2018-03-07 16:32:55
您必须切换最后两个参数的顺序:
从…
return $this->hasMany('App\shopOrderRoutingStepPlan', 'ShopOrder', 'ID');至
return $this->hasMany('App\shopOrderRoutingStepPlan', 'ID', 'ShopOrder');这些参数包括
https://stackoverflow.com/questions/49147206
复制相似问题