#Eloquent: How to model marriage relation between two persons?

1 messages · Page 1 of 1 (latest)

nimble stag
#

How can I get to Person models into a monogamous marriage relationship in my database? But without to have the marriage saved on both models.

Easy peasy solution would be to have a partner_id column in the persons table. With a One To One relationship "partner" between the model. But I would alway have to save the Partner on both model entities. That's what I would like to avoid. But I have no idea how to do that.

I'm open for ideas 🙂

languid lotus
#

I'd use a pivot table with a couple of extra timestamp fields for "married since" and "married until"

nimble stag
#

So your pivot table would have the following columns: id, partner_1_id, partner_2_id, married_since, married_unit?

How would you configure the relation on the model? How would two entites Alice and Bob find the same entry in the pivot table?

languid lotus
#

I guess it's not a type of relationship that would be easy to model for eloquent. I'd need to spend a bit more time thinking about that one.

nimble stag
#

Yes, thats why I am asking. I was already turning my head around this for a while 🙂