Ruby on rails 4 rails4//在添加关系时通过语法有很多
如何将参数传递给has\u many关联 假设我们有类别和帖子,与一个联接表关联,category_postsRuby on rails 4 rails4//在添加关系时通过语法有很多,ruby-on-rails-4,syntax,associations,has-many,Ruby On Rails 4,Syntax,Associations,Has Many,如何将参数传递给has\u many关联 假设我们有类别和帖子,与一个联接表关联,category_posts category has_many category_posts category_has_many posts, through category_posts 和文章的相反方向(不是正确的语法,为了让它在这里快速) 假设我们得到了添加以下内容的基本语法: category.posts << post category.posts您必须直接添加到category\u p
category has_many category_posts
category_has_many posts, through category_posts
和文章的相反方向(不是正确的语法,为了让它在这里快速)
假设我们得到了添加以下内容的基本语法:
category.posts << post
category.posts您必须直接添加到category\u posts
关系中,例如:
category.category_posts << CategoryPost.create(post: post, other_field: other_value)
category.category_posts.create(post: post, other_field: other_value)