Ruby on rails 3.2 Rails混合联接表名中有多个属于多个

Ruby on rails 3.2 Rails混合联接表名中有多个属于多个,ruby-on-rails-3.2,relationship,foreign-key-relationship,rails-activerecord,Ruby On Rails 3.2,Relationship,Foreign Key Relationship,Rails Activerecord,我正在做一个简单的todo应用程序,我只有todo和tag模型,它们之间有很多关系。我还为联接设置了todo_标记迁移,如下所示: class CreateTodoTagsJoinTable < ActiveRecord::Migration def up create_table :todo_tags, :id => false do |t| t.integer :todo_id t.integer :tag_id end add_index :

我正在做一个简单的todo应用程序,我只有todo和tag模型,它们之间有很多关系。我还为联接设置了todo_标记迁移,如下所示:

class CreateTodoTagsJoinTable < ActiveRecord::Migration
 def up
  create_table :todo_tags, :id => false do |t|
    t.integer :todo_id
    t.integer :tag_id
  end

    add_index :todo_tags, [:todo_id, :tag_id]
  end

  def down
   drop_table :todo_tags
  end
 end
结束

和标签 类标记
  has_and_belongs_to_many :todos

  validates_uniqueness_of :tag_name, :on => :create, :message => "Tag name must be unique"

end
还有我的控制器

def destroy
  @todo = Todo.find(params[:id])
  @todo.destroy

  respond_to do |format|
    format.html { redirect_to todos_url }
    format.json { head :no_content }
  end
end

我发现了一些可能是正确答案的东西。在这种情况下,我想我只能通过使用一个我不需要的“有很多通过”关系来扭转局面

请注意,表需要按字母顺序命名,即。 类别\故事表与故事\类别相对-这是 使它起作用的惯例

def destroy
  @todo = Todo.find(params[:id])
  @todo.destroy

  respond_to do |format|
    format.html { redirect_to todos_url }
    format.json { head :no_content }
  end
end