I am am trying to generate data such as the following
[{
"id": 1,
"company": "Doogle",
"contacts": [{
"primary": true,
"first_name": "John",
"last_name": "Doe"
}]
},
{
"id": 2,
"company": "Bahoo",
"contacts": [{
"primary": false,
"first_name": "Peter",
"last_name": "Drake"
},
{
"primary": true,
"first_name": "Jane",
"last_name": "Smith"
}]
}]
Contacts is an array of objects, how do I enforce the rule that one and only one contact can be primary and there must be at least one primary contact?