I am trying to specify a 1:1 relationship, via orgperson(), despite the m:m nature of an existing relationship, orgs(), so that I can eager load 1 default organization.
I have the following objects, each with a table:
- person model - important note, defaultOrgID exists on person
- organization record
- pivot connecting both (orgperson) with additional fields
Is my "jerry-rigging," as shown in the orgperson() function, valid?
If not, is there anything close that would be?
In the Person model, the relevant relationships are as follows:
// many-to-many relationship from person to orgs via org-person table
public function orgs()
{
return $this->belongsToMany(Org::class, 'org-person', 'personID', 'orgID');
}
// "pivot table" with additional fields
public function orgperson()
{
return $this->belongsTo(OrgPerson::class, 'personID', 'personID')
->where([
['orgID', $this->defaultOrgID],
['personID', $this->personID]
]);
}