【发布时间】:2017-02-15 15:20:08
【问题描述】:
在一个小例子中,我有 3 个表(其中 2 个很重要)。 我的表是 PRODUCT、TRANSFER、WAREHOUSE
我想将产品从 1 个仓库转移到另一个仓库,显然这种转移必须在 TRANSFER TABLE 中,我的示例模型可能是下一个。
HERE THE ENTITY - RELATION - MODEL
现在我正在使用 Laravel 5.0 当我创建模型时,我正在这样做,使用 TRANSFER 模型:
<?php namespace Sicem;
使用 Illuminate\Database\Eloquent\Model;
类 TRANSFER 扩展模型{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'TRANSFER';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['id','ware_ori_id','ware_end_id','product_id'];
public function product(){
return $this->belongsTo('Sicem\Product');
}//THIS IS OK!
public function sourceware(){
return $this->belongsTo('Sicem\Warehouse\ware_ori_id');
}//I THINK THIS IS OK!
public function endware(){
return $this->belongsTo('Sicem\Warehouse\ware_end_id');
}//I THINK THIS IS OK!
}
现在,我的问题在我的 WAREHOUSE 模型中,我不知道该放什么:
<?php namespace Sicem;
使用 Illuminate\Database\Eloquent\Model;
类 WAREHOUSE 扩展模型{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'WAREHOUSE';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['id','name'];
public function transfer(){
return $this->hasMany('Sicem\TRANSFER');
}//I supose this.
//But is or not necesary to have 2(two) functions for the relation in my TRANSFER model???????????
}
SIEM:是我的项目名称
请帮帮我。
【问题讨论】:
标签: laravel models has-many belongs-to database-relations