How to manage n-n relationship in this case ?
Hello, I'm having a bit of trouble figuring out how to handle the data registration in the intermediate table in this relationship. I save the framework ID in the 'sheets' table, but once the framework is determined, another select appears and allows choosing skills from this selected framework in the previous select. I was thinking of attaching each skill in the afterCreate() function, but when the resource is edited, it becomes more complicated ...
Part of the Form with selects :
Help would be really appreciated 🙂
31 Replies
Wouldn't framework_competencies be a relationship and as such just saves directly to the relationship?
It could be if a sheet would have every competencies of a competency_framework, however, a sheet can have some but not all competencies of a competency_framework
This is why its a little bit tricky
Can you refind the options with a custom option list based on selections relative to the sheet?
I'm sorry, but I don't understand what you're saying 😬
So I need a better understanding I suppose of what you are trying to do, i.e. with conditions etc
Ok, so I'm trying to save the competencies of a sheet into the pivot table competency_sheet but because I dont use ->relationship() for the input where I select competencies I want ... nothing is currently saved in the DB
The select in question
The best scenario would be to use ->relationship() BUT having only the competencies from the competency framework selected above
But that should work? I suspect your issue is you need to set relationship in the above, but only return the options if you have a framework_id so
cleaner again
No but my options are working fine
But you said the options were returning all?
Everything is working perfectly, its just that competencies selected are not saved in the DB
So to save them to the DB you pass them into by using the ->relationship()
Ah, sorry if you understood taht
I put ->relationship() on the select on top of the ->options() ?
I didn't see that in this. ?
But yes you would tend to do that. Are you syaing if you define it's a relationship it's still not saving them as a relationship?
and your model for the relationship has sheetFramework as the relationship class? Try updating the select name to be sheetFramework too if that is the relationship name on the model.
Ok so I added relationship and it worked ... My bad honestly I didn't thought it was possible to have ->relationship() and ->options on a select because for me ->relationship() is already creating the options
But I have another problem
Idk if its due to ->relationship()
Now the competencies options are not refreshed when I change the framework
Framework 2 have C2.1 .... C2.2 ... etc
Is the framework coded to be ->live() ?
Oh ok I'm dumb ahaha
Yes its live
but I didnt renamed the afterStateUpdate
and I renamed the input ...
😉
Ah, nope
so now it clear the competencies selected
But the options are still the one of the first framework selected, they are not refreshed
They should be refreshed, but as a hacky solution, afterStateUpdated() you can load the records and uset the setter to set that relationships' options based on the selection, but only once it is shown.
It's important to note, it can only be updated if it's shown.
Ok so because its hidden it didnt refresh the query, but I dont understand when you say "you can load the records"
I tried without hidding the input and it works well but revealing the input when a framework is selected is better
I don't understand how I can use afterStateUpdated() for changing the options query
You can first try it with disabled opposed to hidden.
Yes, so it looks like when a select is disabled you can still write in it 😮
It should be non-clickable
Yes its weird
Ahh you have searchable, so you can search but not select. Disable searchable too when you want it disabled
Ah ok thanks a lot, I will do that 🙂
I just looked and I dont have searchable, its the multiple(). And know I no longer can search in it when disabled (I have changed nothing 😅 ) but I have another bug ... I can't open the select and it don't have placeholder 😬