i'm trying understand how implement one-to-many relationship through reference table. i'm looking on this guide though write on 1 model has_many one-to-many i'm not sure (i wrote it's not working). anyway i'm doing save me table, , doing right , not working. the model following: microposts, :id, :content tag, :id, :name tag_microposts, :tag_id, :micropost_id article, :id, :text article_microposts, :article_id, :micropost_id i can 2 microposts tables id of tag/article. think doing better , righter. in end what's interesting me microposts through tag model. in tag_controller able do: def index @tag = tag.find(params[:id]) @microposts = @tag.microposts end some code: class tag < activerecord::base ... has_many :tag_microposts, foreign_key: :tag_id, dependent: :destroy has_many :microposts, through: :tag_microposts, source: :micropost ... end class tagmicropost < activerecord::base validates :tag_id, presence: true v...
Comments
Post a Comment