Reputation: 173
I have a package with a given declared 'Category' relation as follow:
public function category()
{
return $this->belongsTo(ProductCategory::class);
}
In the application implementing the package, the relation is redefined as follow:
public function vintage()
{
return $this->belongsTo(Vintage::class, 'vintage_id', 'id');
}
public function category()
{
return $this->vintage();
}
When eagerloading the "Vintage" relation on the application side all is good, but it doesn't on the package side. Everytime the package tries to refer to the "Category" relation, it triggers a call to the SQL database to load the "Category" relation - which I'm trying to avoid.
My question; is there any way to "alias" (or whatever you my call it), to have the relation "Vintage" acting the same as "Category" within the package?
I know when loading a relation it appears "as it's defined" in the list of relations. One option I'm looking at is to load both relations on the application side so the package can find it without generating a SQL call.
Upvotes: 1
Views: 37