我有3张桌子
1.categories
id int(11) Auto Increment
categoryname varchar(35)
2.Products
id int(11) Auto Increment
category_id int(11)
skunumber varchar(35)
image varchar(255)
name varchar(35)
size varchar(12)
stock int(11)
cu_price decimal(10,0)
margincost decimal(10,0)
3.promotionproducts
id int(11) Auto Increment
promotion_id int(11)
product_id int(11)
我也有3个模态,这些是
class Category extends Model {
//
public function product() {
return $this->hasMany('App\Product', 'category_id');
//return $this->belongsTo('App\Promotion', 'promotion_id');
}
}
class Promotion extends Model {
//
public function promotionproduct() {
return $this->hasMany('App\Productoffer', 'promotion_id');
}
}
class Productoffer extends Model {
protected $table = 'promotionproducts';
//
public function promotion() {
return $this->belongsTo('App\Promotion', 'promotion_id');
}
}
现在我想根据category_id关联类别或促销。我怎样才能在他们之间建立关系