So I have three entities...
Contract (id, name, services)
Service (id, name, recommendedPrice)
ContractService (client_id, service_id, adjustedPrice)
I would like to have a form for creating/editing a 'Contract', that displays a checkbox for each possible 'Service', and a text field for the adjusted price of that service.
I have spent days trying to figure out the best way to structure all of this and am having a really hard time. I would assume it is similar in design to a form you would use to enable/disable permissions for a user, but I cannot find any good examples.
Right now I have my 'Contract' entity, which has an oneToMany association to its 'ContractServices', as a Contract can have many ContractServices. The 'ContractServices' entity has a manyToOne association to 'Services', is manyToOne correct here?
When I try to use the ContractServiceType form to collect services, I get no data on the form unless I have assigned one or more dummy 'ContractService' entities to the 'Contract' entity prior to rendering the form (similar to the task/tags embedded form tutorial on the Symfony site).
Also, once the data is persisted, the 'ContractServiceType' forms start duplicating, once for the dummy and again for any that have been persisted to the database for that 'Contract'. This is the closest I've been so far, so I decided I could write logic in the controller to decide which dummy entities to create later, based on which have already been associated with the 'Contract', though it seems like there should be a better solution.
So my solution right now is to use the 'Service' entity repo, to query for all unique 'Services', and then use those services to generate a number of dummy 'ContractService' entities to use when the form is built. It yields what I am looking for, in that I get a checkbox(to "enable") and adjustedPrice field for each of the possible 'services'.
Is this the best way to handle this?
If so, is there a way to reference the associated 'Service' name (should be available via the joined table?) in the ContractService form builder?