mammoth-guitar-49791
06/13/2023, 5:35 PMdancer
:has_many couples and has a profile_image
From the couple I would like to display the dancer image. Is there a reference somewhere on how to do something like this? 🤔lemon-wall-20836
06/13/2023, 5:41 PMlemon-wall-20836
06/13/2023, 5:41 PMlemon-wall-20836
06/13/2023, 5:41 PMlemon-wall-20836
06/13/2023, 5:41 PMmammoth-guitar-49791
06/13/2023, 5:42 PMruby
# frozen_string_literal: true
class CoupleResource < Avo::BaseResource
self.title = :dancer_names
self.includes = [:dancer, :partner, :videos]
self.search_query = -> do
scope.ransack(id_eq: params[:q], m: "or").result(distinct: false)
end
field :id, as: :id
field :dancer, as: :belongs_to
field :dancer_image, as: :file, is_image: true, is_avatar: true do
model.dancer.profile_image
end
field :partner, as: :belongs_to
field :partner_image, as: :file, is_image: true, is_avatar: true, format_using: ->(model) { model.partner.profile_image }
field :videos_count, as: :number do
model.videos.length
end
field :slug, as: :text
field :unique_couple_id, as: :text, hide_on: [:index, :show]
field :couple_videos, as: :has_many
field :videos, as: :has_many, through: :couple_videos
end
ruby
class Dancer < ApplicationRecord
belongs_to :user, optional: true
has_many :dancer_videos, dependent: :destroy
has_many :videos, through: :dancer_videos
has_many :orchestras, through: :videos
has_many :songs, through: :videos
has_many :couples, dependent: :destroy
has_many :partners, through: :couples
has_many :performances, through: :videos
has_one_attached :profile_image
has_one_attached :cover_image
ruby
class Couple < ApplicationRecord
belongs_to :dancer
belongs_to :partner, class_name: "Dancer"
has_many :couple_videos, dependent: :destroy
has_many :videos, through: :couple_videos
lemon-wall-20836
06/13/2023, 5:44 PMlemon-wall-20836
06/13/2023, 5:44 PMmammoth-guitar-49791
06/13/2023, 5:44 PMlemon-wall-20836
06/13/2023, 5:45 PMruby
field :photo, as: :file do |model|
model.dancer.profile_image
end
mammoth-guitar-49791
06/13/2023, 5:46 PMruby
field :dancer_image, as: :file, is_image: true, is_avatar: true do
model.dancer.profile_image
end
something like this?lemon-wall-20836
06/13/2023, 5:46 PMmammoth-guitar-49791
06/13/2023, 5:47 PMweb |
web |
web |
web | ActiveRecord::AssociationNotFoundError (Association named 'dancer_image_attachment' was not found on Couple; perhaps you misspelled it?):
web |
web | rails (d137b10f946f) activerecord/lib/active_record/associations.rb:302:in `association'
web | rails (d137b10f946f) activerecord/lib/active_record/associations/preloader/branch.rb:79:in `block in grouped_records'
web | rails (d137b10f946f) activerecord/lib/active_record/associations/preloader/branch.rb:77:in `each'
web | rails (d137b10f946f) activerecord/lib/active_record/associations/preloader/branch.rb:77:in `grouped_records'
web | rails (d137b10f946f) activerecord/lib/active_record/associations/preloader/branch.rb:114:in `loaders'
web | rails (d137b10f946f) activerecord/lib/active_record/associations/preloader/branch.rb:71:in `runnable_loaders'
lemon-wall-20836
06/13/2023, 5:48 PMhas_one_attahced
on dancermammoth-guitar-49791
06/13/2023, 5:49 PMmammoth-guitar-49791
06/13/2023, 5:49 PMmammoth-guitar-49791
06/13/2023, 5:49 PMlemon-wall-20836
06/13/2023, 5:52 PMlemon-wall-20836
06/13/2023, 5:52 PMlemon-wall-20836
06/13/2023, 5:52 PMmammoth-guitar-49791
06/13/2023, 5:53 PMmammoth-guitar-49791
06/13/2023, 5:53 PMlemon-wall-20836
06/13/2023, 5:54 PMlemon-wall-20836
06/13/2023, 5:54 PMdo |model|
lemon-wall-20836
06/13/2023, 5:55 PMlemon-wall-20836
06/13/2023, 5:55 PMlemon-wall-20836
06/13/2023, 5:56 PMfield :dancer_image, as: :file, is_image: true, is_avatar: true do
fieldlemon-wall-20836
06/13/2023, 5:59 PMdo |model|
arguments. weirdlemon-wall-20836
06/13/2023, 6:00 PMmammoth-guitar-49791
06/13/2023, 6:00 PMlemon-wall-20836
06/13/2023, 6:01 PMlemon-wall-20836
06/13/2023, 6:19 PMlemon-wall-20836
06/13/2023, 6:19 PMlemon-wall-20836
06/13/2023, 6:28 PMmammoth-guitar-49791
06/13/2023, 6:29 PMlemon-wall-20836
06/13/2023, 6:30 PMlemon-wall-20836
06/13/2023, 6:30 PMlemon-wall-20836
06/13/2023, 6:30 PMmammoth-guitar-49791
06/13/2023, 6:30 PMlemon-wall-20836
06/13/2023, 6:37 PMmammoth-guitar-49791
06/13/2023, 6:47 PMgem "avo", git: "https://github.com/avo-hq/avo.git", branch: "fix/stop-eager-loading-computed-file-fields", ref: "1789"
mammoth-guitar-49791
06/13/2023, 6:48 PMlemon-wall-20836
06/13/2023, 6:48 PMref
lemon-wall-20836
06/13/2023, 6:48 PMmammoth-guitar-49791
06/13/2023, 6:50 PMlemon-wall-20836
06/13/2023, 6:51 PMbin/rails avo:build-assets
mammoth-guitar-49791
06/13/2023, 6:53 PMlemon-wall-20836
06/13/2023, 6:56 PMmammoth-guitar-49791
06/13/2023, 6:58 PMmammoth-guitar-49791
06/13/2023, 6:58 PMmammoth-guitar-49791
06/13/2023, 6:58 PMlemon-wall-20836
06/13/2023, 6:58 PMmammoth-guitar-49791
06/13/2023, 7:01 PMlemon-wall-20836
06/13/2023, 7:01 PMlemon-wall-20836
06/13/2023, 7:01 PMlemon-wall-20836
06/13/2023, 7:01 PMlemon-wall-20836
06/13/2023, 7:02 PMlemon-wall-20836
06/13/2023, 7:02 PMmammoth-guitar-49791
06/13/2023, 7:02 PMlemon-wall-20836
06/13/2023, 7:02 PMlemon-wall-20836
06/13/2023, 7:03 PMlemon-wall-20836
06/13/2023, 7:09 PM2.34.6
in a second with these fixes