Since a product_accessory_adaptor relates to a product and a catagory, why don't you create a ProductAccessoryAdaptor model with two belongs to relationships ?
hi pmall, the ProductAccessoryAdaptor model would not have a direct foreign key..Could you advise how is that doable? I've updated my question as well with regards on what i've achieved so far.
Why is this not suited ?
Schema::create('product_accessory_adaptor', function(Blueprint $table)
{
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->integer('accessory_id')->unsigned();
// more fields...
$table->foreign('product_id')->references('id')->on('accessories');
$table->foreign('accessory_id')->references('id')->on('accessories');
}
then
class Adaptor extends Eloquent {
protected $table = 'product_accessory_adaptor';
public function products() {
return $this->belongsTo('Product');
}
public function accessories() {
return $this->belongsTo('Accessory');
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community