ruby - Retrieve polymorphic associations in Rails from one model -
class user < activerecord::base has_many :posts has_many :images, as: :imageable end class post < activerecord::base belongs_to :user has_many :images, as: :imageable end class image < activerecord::base belongs_to :imageable, polymorphic: true end
is there specific way can user.images , both user's images , post's images belong user?
for reason can't wrap head around how best.
in case can avoid polymorphic relationship, simple has_many
, belongs_to
suffice. :
class user activerecord::base has_many :posts has_many :images end class post activerecord::base belongs_to :user has_many :images end class image < activerecord::base belongs_to :post belongs_to :user end
but again think wanted ask user.last.images
, not user.images
Comments
Post a Comment