radum - #? in debug bar i can see this query se...
# ❓questions
r
#? in debug bar i can see this query select * from
blocks
where
blocks
.
blockable_type
= 'oferteMasinis' and
blocks
.
blockable_id
= 94 and
blocks
.
blockable_id
is not null order by
blocks
.
position
asc where oferteMasinis is my table name but in the db i can see in the blockable_type the model name 'App\Models\OferteMasini'. what is the problem?
i
Hi @radum you seem to be missing a morphmap for your OferteMasini model
r
since i added this to the appServiceProvider i think it's stoped working ... public function boot() { Relation::morphMap([ 'oferteMasinis' => 'App\Models\OferteMasini', 'noutatiAutos' => 'App\Models\NoutatiAuto', ]);
looks like the morph map was the other way around. i had it as in the documentation
i
I'm sorry but your change in the docs is incorrect. See the Laravel documentation: https://laravel.com/docs/10.x/eloquent-relationships#custom-polymorphic-types. You are going in that direction because you created data before setting it up. When you add a morphmap after the fact in Laravel, the db data doesn't update itself and so relationship don't work anymore. This is fixed quickly with a migration that changes the values in polymorphic types columns, like blockable_type.