Support the ongoing development of Laravel.io →
Eloquent Laravel
Last updated 2 weeks ago.
0

@gibsonjareds do you see the '0' and '1' in the database? My first idea is that it suggest that you have a enforceMorphMap call where the array doesn't have an index.

But if it is the case I should suggest to also change that to the version used in your morphMap and run a migration to update the values.

1

@tvbeek I’m afraid I’ve been unclear. I have 274 records in the table - let’s call this table A - that uses 0 or 1 to refer to which model it maps to. This was designed nearly a decade ago and is used in a legacy API. Table B uses a column that contains an actual model name.

I have solved how to map the polymorphic relationships for table B, but I need to know if there’s a way for me to overwrite the mapping only on the relationships that refer to table A.

0

@gibsonjareds can you show the code that you use in your model to get the relation for table A? That can help in thinking about a solution.

And is the problem only about loading the data or also about storing?

1

@tvbeek thanks for the question asking. I have just overwritten the getActualClassNameForMorph on the model for table A to handle these specific cases, and that seems to be working well.

0
Solution selected by @gibsonjareds

@gibsonjareds that is a nice solution :)

0

Sign in to participate in this thread!

LaraJobs

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.