Answer the question
In order to leave comments, you need to log in
How is the duplication of these relationships organized?
There is a location object with a large number of relationships (region, district, town, house number, and so on)
class PropertyLocation extends Model
{
public function district()
{
return $this->hasOne(LocationDistrict::class);
}
public function region()
{
return $this->hasOne(LocationRegion::class);
}
public function route()
{
return $this->hasOne(LocationRoute::class);
}
public function settlement()
{
return $this->hasOne(LocationSettlement::class);
}
....
}
Answer the question
In order to leave comments, you need to log in
As I understand it, there is nothing special, as you wrote, store fields other than region_id, also region_name, etc. In order for everything to be updated correctly, you can hang a trigger to save the location and check if $location->isDirty(['region_id'])
, then update region_name before saving to the database.
To update the region and the like, you can also hang a trigger in Laravel, or you can directly on the base, and use this trigger to update the names of all locations tied to it.
PS. As far as I understood, you should have belongsTo instead of hasOne.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question