Skip to main content
added 241 characters in body
Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

Add a field main_address_id in the User entity or table that holds the ID of the Address record that is the main one. Make that a one to one relationship, if you like.

The only solution I have now is to create another One-to-One relationship between Users.main_address and Address but this does not insure that the main_address will actually be part of the User.addresses collection.

Quite right. You need another mechanism that insures that. You can either validate that in your business logic, or use a stored procedure or trigger on the RDBMS during creation or editing of User that enforces this restriction.

Doctrine might have a "business rules" module that you can use. The point is that the additional restriction you are imposing on main_address_id doesn't have anything to do with your database schema, per se. It's a business rule, basically.

Add a field main_address_id in the User entity or table that holds the ID of the Address record that is the main one. Make that a one to one relationship, if you like.

The only solution I have now is to create another One-to-One relationship between Users.main_address and Address but this does not insure that the main_address will actually be part of the User.addresses collection.

Quite right. You need another mechanism that insures that. You can either validate that in your business logic, or use a stored procedure or trigger on the RDBMS during creation or editing of User that enforces this restriction.

Add a field main_address_id in the User entity or table that holds the ID of the Address record that is the main one. Make that a one to one relationship, if you like.

The only solution I have now is to create another One-to-One relationship between Users.main_address and Address but this does not insure that the main_address will actually be part of the User.addresses collection.

Quite right. You need another mechanism that insures that. You can either validate that in your business logic, or use a stored procedure or trigger on the RDBMS during creation or editing of User that enforces this restriction.

Doctrine might have a "business rules" module that you can use. The point is that the additional restriction you are imposing on main_address_id doesn't have anything to do with your database schema, per se. It's a business rule, basically.

Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

Add a field main_address_id in the User entity or table that holds the ID of the Address record that is the main one. Make that a one to one relationship, if you like.

The only solution I have now is to create another One-to-One relationship between Users.main_address and Address but this does not insure that the main_address will actually be part of the User.addresses collection.

Quite right. You need another mechanism that insures that. You can either validate that in your business logic, or use a stored procedure or trigger on the RDBMS during creation or editing of User that enforces this restriction.