Select with BelongsToMany without multiple()?
Trying to work with an existing model setup. Have two relationships. One just gets a list of contacts and you can pick multiple. The other lets you simple pick 1 as your primary contact. They are both stored in the same table, there is just an additional boolean column for setting it as primary or not. Everything works great for loading the relationship and saving at this point, but I obviously dont want multiple() for the primary contact. Suggestions? The primary relationship is something like with ->contacts() being a
belongstomany()
. Im using saveRelationshipsUsing() to handle the saving part. Like I said, everything works great except for multiple() requirement as Select wont work with belongstomany().7 Replies
i think its a flaw in the db structure
if its not possible in the business domain, it shouldnt be possible in the db
you should use a
primary_contact_id
on the table and then a simple BelongsTo
the only other way you could do it is creating a select dehydrated(false)
, manually defining options, and then inside saveRelationshipsUsing() use $get and attach the pivot.
how is the existing record selected for the primary_housing_locator?
select the primary, and then the rest
oh
you mean when loading?
idk, you choose
just fill your form with the primary locator
its a custom form so you choose how to fill that property
its not really a custom form, im just filling it with EditRecord on a table. I can modify what its given though I guess.
EditAction? i think theres a mutate function for that
How do i even fill a select without a relationship? I have options taken care of, but how do select the existing value? passing an id just puts an id in the box, but thats obviously not what i want displayed.
If there’s an option with that key then setting the selection is automatic based on the data.