Ruby on rails weired语句在rails 3中构建多对多关系表单时出现无效错误
您好,我正在制作一个表单,用于在两个模型之间建立多对多关系 用这个 我有三个模型 艺术家、文章、艺术关系 这是艺术家模型Ruby on rails weired语句在rails 3中构建多对多关系表单时出现无效错误,ruby-on-rails,rails-activerecord,Ruby On Rails,Rails Activerecord,您好,我正在制作一个表单,用于在两个模型之间建立多对多关系 用这个 我有三个模型 艺术家、文章、艺术关系 这是艺术家模型 class Artist < ActiveRecord::Base default_scope order('created_at DESC') attr_accessible :body_en, :body_kr, :title_en, :title_kr has_many :articles, :through => :artist_r
class Artist < ActiveRecord::Base
default_scope order('created_at DESC')
attr_accessible :body_en, :body_kr, :title_en, :title_kr
has_many :articles, :through => :artist_relationships
has_many :artist_relationships
end
它引起了这些错误
Mysql2::错误:列“created_at”in order子句不明确:从artists
上的artists
id
=artists\u relationships
艺术家id
其中article\u-id
=1和艺术家
id
=2按描述限制1创建的订单
我不明白它的意思
当我在代码上方使用pry进行调试时,就会发生类似的事情
<%= check_box_tag :artist_ids, artist.id, article.artists.include?(artist), :name => 'article[artist_ids][]' %>
“文章[艺术家ID][]”%>
当我直接呼叫article.artists.include?(artist)
这引起了和我预料的一样的错误。但是
当我调用article.artists
时,它返回属于该文章的艺术家数组
然后我再次调用article.artists.include?(artist)
。我工作很好
这有什么问题?在所有默认范围中,包括类的表格化版本
# article.rb
default_scope order('articles.created_at DESC')
谢谢你的回答!
<%= form_for [:admin, article] do |f| %>
.....
<% Artist.all.each do |artist| %>
<div>
<%= label_tag :artist_ids, artist.title_kr %>
<%= check_box_tag :artist_ids, artist.id, article.artists.include?(artist), :name => 'article[artist_ids][]' %>
</div>
<% end %>
article.artists.include?(artist)
<%= check_box_tag :artist_ids, artist.id, article.artists.include?(artist), :name => 'article[artist_ids][]' %>
# article.rb
default_scope order('articles.created_at DESC')