I was wondering if there's a way to create a `belo...
# avo-2
t
I was wondering if there's a way to create a
belongs_to
in an action? The use case is I have
ModelA
that
has_many
ModelB
and I'd like to be able to use the
record_selector
to check several
ModelB
, choose
Actions
, and then select
"Assign ModelA"
action. This should cause a modal with a select box to appear with all the records from
ModelA
, such that when I submit it, the ID for the selected
ModelA
is sent to the server, where I can deserialize it from the
fields
object.
l
Hey there. Author of Avo here
Most probably you’re not going to achieve it that way. You could add a select field and manually populate the options with the associated records
That’s not going to work because it needs the model and it’s not going to be attached in that way
Try what I said above and let me know if it worked
t
That’s not convenient since you cannot declare a select field searchable and the model in question has over 10,000 rows.
l
Got it. Makes sense
You could create a custom field that requests the records from a controller
t
I see, and then scope the query to reduce the results.
l
Yes
You could use the search path that returns a json
t
It would be very useful to inject a class to reflect against in the actions to be able to access the belongs_to relationship. I found a similar add on for ActiveAdmin.
l
And in the search_query listen for a param that you send from the field
That sounds nice
Please send in a PR
t
For sure! I’ll see if I can come up with something.
https://github.com/avo-hq/avo/pull/1206/files PR for the feature, as discussed. I can update the specs if necessary as well as the docs, but I wanted to send it over first beforehand. I did not enable it for polymorphic relationships.
l
Sure. That’s perfect
I’ll have a look in the following days