活动记录 - 添加对现有连接表的引用

时间:2017-10-18 12:35:07

标签: mysql ruby-on-rails join rails-activerecord

问题是:某些“ PointOfInterest ”有一些“类别”所以这是一个NN关系(我有一个 pointID 的表格,的的categoryID ) 现在我必须添加一个名为“行程”的新模型,我想使用我在PointOfInterest和Category之间使用的相同连接表,这是可能的吗?以及我如何做到这一点?

此处 PointOfInterest与类别之间关系的迁移代码

class CreatePointOfInterestPointOfInterestJoinTable < ActiveRecord::Migration
  def change
    create_table :point_of_interest_categories_point_of_interests, id: false do |t|
    t.integer :point_of_interest_id
    t.integer :point_of_interest_category_id
  end

  add_index :point_of_interest_categories_point_of_interests, :point_of_interest_category_id, name: 'poi_category'
  add_index :point_of_interest_categories_point_of_interests, :point_of_interest_id, name: 'poi'

  end
end

p.s:对不起我的英语:)

0 个答案:

没有答案
相关问题