Cannot work with multiple model key types. #3745
Unanswered
irealworlds
asked this question in
Ideas
Replies: 2 comments
-
I think this is a problem you'd get regardless. Generally, I'd say its always best practice to have an ID for a record, and then if you want to use UUID's have a secondary column that stores the UUID. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Лучший вариант, в данном случае, это использование разных моделей/таблиц, что я пытаюсь сейчас сделать, но по какой-то причине, пакет не особо волнует, что я тут добавил. use Spatie\MediaLibrary\MediaCollections\Models\Media;
class OtherMedia extends Media
{
protected $table = 'other_media';
} public function media(): MorphMany
{
return $this->morphMany(OtherMedia::class, 'model');
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As it currently stands, it is not possible to use this library (out of the box) when working with models with multiple key types (i.e. numeric ids on some models, but uuids on others).
I am using UUIDs for most of my models, so I modified the Media table migration to use uuids for
model_id
, but some use integers.I could not find any way to achieve this other than a hacky solution like this, which is not DB agnostic and involves creating a custom trait
The best solution I could think of is changing
model_id
to ajson
column and using a json representation of the actual model id for all models, but this requires a change in theHasMedia
contract as well as theInteractsWithMedia
trait, because then the relation returned bymedia()
is no longerMorphMany
, but aHasMany
.Beta Was this translation helpful? Give feedback.
All reactions