Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ohildn's avatar

Custom belongsTo Relationship

Hi,

I have a model of activities that's connected to a location-model with "location_id" as foreign key. Classic belongsTo relationship.

The location model is in another app that's connected with the app I am hosting the activities on. No problem so far, I can still build a normal belongsTo relationship because I have access to both models.

My problem is that the location model needs to be altered in a service-class before being processed in my app. (only pick out some attributes that will be renamed and merged too. It's an old model and I don't want to make the new app dependent on those attribute-names that follow no convention at all).

Is there a way to build up a relationship between this service-class that returns a default collection of locations and my activities model with keeping the possibility to eagerload it using the with() method?

0 likes
0 replies

Please or to participate in this conversation.