I’m using an ORM (SQLAlchemy, but my question is quite implementation-agnostic) to model a many-to-many relationship between a parent class and its children.. I was wondering, what would be a simple way to express the concept ‘one of the children is the default/main one’?
For example, I’d need to persist the following:
This Person instance has Address X and Y, the main one is Y.
I saw this implemented using a ‘middle’ class like ‘PersonAddressRelation’ that would contain ‘Person’, ‘Address’ and the ‘main’ flag, but I think it looks a bit cumbersome.. Is there a better way?
The simplest way would be to have a join table, PersonAddressRelation, and also a DefaultAddress column on the Person table that keys to the Address table.