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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -