我有以下两种型号:
class Store < ActiveRecord::Base
belongs_to :person
end
class Person < ActiveRecord::Base
has_one :store
end
问题是:我正在try 创建一个迁移,以便在people表中创建外键.然而,引用Store外键的列并不像rails惯例那样被命名为store_id,而是被命名为foo_bar_store_id.
如果我遵循rails惯例,我会这样做:
class AddReferencesToPeople < ActiveRecord::Migration
def change
add_reference :people, :store, index: true
end
end
但是,这将不起作用,因为列名不是store_id,而是foo_bar_store_id.那么,如何指定外键名只是不同,但仍然保持index:true以保持快速性能呢?