Tried to find a solution, but couldn’t find a similar problem.
I have two classes: Product
and TempProduct
. Both inherit from BaseProduct
.
BaseProduct doesn’t have a table name defined, but Product and TempProduct do.
I also have an Order model that has the following relation:
public function products()
{
return $this->morphTo('products', 'product_type', 'product_id');
}
The product_type column is an enum with values “product” or “product_temp” to indicate which table the product comes from.
Then I have a Shop model that is connected to Order:
public function shop_order()
{
return $this->hasMany(Order::class, 'order_id', 'id')->withTrashed();
}
Previously, before adding TempProduct, I used the following hasManyThrough relation:
public function products_sell()
{
return $this->hasManyThrough(Product::class, Order::class, 'order_id', 'id', 'id', 'product_id');
}
Now that I’ve added TempProduct and switched to a polymorphic relation, I’m not sure how to implement hasManyThrough in this case.