You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like I'm not able to map a many-to-many relationship across a join table using Laravel polymorphic relations.
I can however simulate half the solution by shoehorning a where clause into my relation method:
(the polymorphic columns are stored on the join table, and the join table goes out on a normal relation to the other class, although it might be nice to have double polymorphic relations in the future too!)
public function roles() {
return $this
->belongsToMany(
'MyNamespace\MyPackage\Model\Role',
'table_memberships',
'authorizable_id'
)
->where('authorizable_type', '=', get_called_class())
;
}
...unfortunately this doesn't set the string when calling save(). I suspect this is just a matter of combining the current many-to-many relation with a sprinkle of the morph-one-or-many or morph-many classes.
The text was updated successfully, but these errors were encountered:
It looks like I'm not able to map a many-to-many relationship across a join table using Laravel polymorphic relations.
I can however simulate half the solution by shoehorning a where clause into my relation method:
(the polymorphic columns are stored on the join table, and the join table goes out on a normal relation to the other class, although it might be nice to have double polymorphic relations in the future too!)
...unfortunately this doesn't set the string when calling
save()
. I suspect this is just a matter of combining the current many-to-many relation with a sprinkle of the morph-one-or-many or morph-many classes.The text was updated successfully, but these errors were encountered: