https://avo.cool logo
Hey again 😅
# general
e
Hey again 😅 I'd like to create the action 'Change Account Ownership'. I need a select field that has all the has_many membership records in them. Is there a way to do this? Video in thread.
l
Hello @early-leather-2501 it's ok to be an unsearchable select?
I.E a select with all options rendered
e
I'd like to have a select of account.active_memberships But without the current owner.
Copy code
def fields
  field :active_memberships, as: :belongs_to
end
This gives me a select box of all Membership record. Not associated to the account
l
hmm, on the
Avo::Resources::Membership
on the search query, when the search is made from the action i think there is some params that indicates it
than the returned query can be changed for this particular search
Let me play with it 5 minutes
e
Thanks Paul!
l
I see 3 possibilities here 1 - Use the paarams inside search query and when (pseudo code)
via_reflection_class=="Account" && via_parent_resource_id == nil && via_parent_resource_class == nil
do
query.where(account: params[:via_reflection_id])
before applying the ransack search
this method use some internal params that can be changed or not
2 - Use tags field wiht
fetch_values_from
where you implement a custom enpoint, you pass all what you need as param to that endpoint and return the wanted collection https://docs.avohq.io/3.0/fields/tags.html#fetch_values_from
3 - Use a select field with pre-populated options calculated bassed on
record
using computed options
I would suggest to go with option 3 if your select dont get a lot of options
option 1 or 2 if select can have a lot of options
e
option 3 did the trick! Thanks! 🙏
Copy code
field :new_owner, as: :select, options: -> { record.active_memberships.includes(:user).where.not(role: 'owner').map {|membership| [membership.user.email, membership.id]} }
l
Cool! Anytime! You lose the search but for little options it's ok