lundi 19 décembre 2016

Eloquent "Proxy/Wrap" Relationship

Say I have a Person model that holds a person's data like name, birthdate, SSN, etc.

I have several other models eg. Profile or Employee that contain all data from the Person model.

Traditionally you could just duplicate all those fields for profile, employee models/tables.

Even better, you can also define a hasOne() relationship in profile or employee, but that way every consumer of that model has to be aware that it's

$employee->person->name;

// Instead of

$employee->name;

My idea is that Employee could have a direct/transparent name field, that would be silently fetched to/saved from an underlying Person model

It's a kind of proxyOne() or wrapOne() relationship.

Does such thing already exist?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire