Replies: 2 comments 2 replies
-
I'm trying to do exactly this, but it seems not possible without manually managing the morphed relationships. I got as far as SQL telling me that entity_assignable_type doesn't have a default value, but all other values are passed correctly when using:
My only option right now is to split up the tables (like you've already mentioned) in order to ensure that I can use the attach() / detach() methods. While this isn't exactly a problem, it will create an additional tables for each assignment type I want to have. Did you ever find any success? |
Beta Was this translation helpful? Give feedback.
-
you can currently fake this relationship by using the /**
* Retrieve the "tags" relationship.
*/
public function tags(): MorphToMany
{
return $this->morphToMany(Tag::class, 'taggable', relatedPivotKey: 'tagger_id')
->withPivotValue('tagger_type', Tag::class);
} I also have a branch currently in progress to bring this as a first-party feature to the framework, just gotta get off my butt and finish it. |
Beta Was this translation helpful? Give feedback.
-
Actually the framework doesn't support a relationships described on the title.
Anyways, i wanna suggest some idea.
When you have an application and that application starts to growth, the database maintenance starts to be a problem, specially when you're a code optimizer and monolith creator.
Given the following scenario:
Well, it's very simple. In the other case you should have
group_user
,user_vehicle
,house_vehicle
tables and more.A single table of relations. With double morph columns.
Extends MorphsToMany or create a new relationship to supports double morphs in pivot table.
Beta Was this translation helpful? Give feedback.
All reactions