我有三个表问题,标签,&的 IssuesLabel
issues.rb
class Issue < ActiveRecord::Base
has_and_belongs_to_many :labels
end
labels.rb
class Label < ActiveRecord::Base
has_and_belongs_to_many :issues
end
issues_label.rb
class IssuesLabel < ActiveRecord::Base
belongs_to :issue
belongs_to :label
end
当我致电issue.labels.find_or_create_by(name: 'bug')
一个问题时,
和issue.labels.find_or_create_by(name: 'bug')
针对其他问题,它会在Labels
表中为bug
我希望它能找到现有的bug
记录,并在IssuesLabel
联接表中添加一个条目。我在这里缺少什么?