class Photo < ApplicationRecord
has_many :user_comments
has_many :users, through: :user_comments
has_attached_file :image
validates_attachment_content_type :image, content_type: /\Aimage/.*\z/
end
class User < ApplicationRecord
has_many :user_comments
has_many :photos, through: :user_comments
end
class UserComment < ApplicationRecord
belongs_to :photo
belongs_to :user
end
执行[union = UserComment.joins(:user,:photo).where('photos.id =?',1).first] - 确定
执行[union.image] - 错误 NoMethodError:#UserComment的未定义方法`image':0x007fe8845fbf58
如何解决?