https://avo.cool logo
Avo - Ruby on Rails Admin Panel Framewor...
# general
m
However, can I also somehow show this
attending
field in the table view in the corresponding parent record?
l
Hi @millions-exabyte-27721 how would you access attending when you have an instance of an participant?
participant.attending
?
participant.something.attending
?
m
hm, good question... actually, maybe I can flip it upside down, i.e. use the
event_participations
join table and display some additional fields that I can delegate to the
user
?
l
there isn't any way to access attending from a participant right now?
m
well a participant is just a user, and they are linked to the events via the
event_participations
table. so
attending
doesn't really make sense in the scope of only a user
you'd always have to join to a certain
event_id
l
how are you rendering those participants table?
what I want to figure out is how to render the attending there
it is possible
something like:
Copy code
ruby
field :attending do
  # Replace get_attending_attribute with the real way to get that attribute
  record.get_attending_attribute
end
m
ah, sorry here's the field definition:
Copy code
rb
    field :participants,
          as: :has_many,
          through: :event_participations,
          show_on: :edit,
          searchable: true,
          attach_fields: -> {
      field :attending, as: :boolean
    }
on the model, participants is just an alias to user:
Copy code
rb
  has_many :participants, through: :event_participations, source: :user, class_name: "User"
so the participants table is just a
users
table
so I should really swap it around. something like
Copy code
rb
field :event_participations, as: :has_many # etc.
Copy code
rb
# event_participation resource
field :attending, as: :boolean
field :email, ...
on the event_participation model:
Copy code
rb
delegate :email, to: :user
I think that looks about right?
l
It helps if we think first, how to achieve this on rails, then translate it to avo
maybe you can reach to that attending boolean with your current setup but with some extra queries only to render that field
m
you are absolutely right
I just got it upside down 🙈
thanks for listening
l
If it's a project on early stage you can still move things arround easly
anytime!
l
I read this quickly, so I may have not understood the requirement, but I think you could create a new resource with custom fields that would use that association
Copy code
ruby
field :custom_event_participations, for_attribute: :event_participations, use_resource: SOME_CUSTOM_RESOURCE, as: :has_many