【发布时间】:2015-07-23 02:09:32
【问题描述】:
所以我在我的 2 个模型之间定义了一个 has_and_belongs_to_many 关系,如下所示
class Client < ActiveRecord::Base
attr_accessible :first_name, :last_name, :email
has_and_belongs_to_many :themes, class_name: 'XY::Theme'
end
class XY::Theme < ActiveRecord::Base
has_and_belongs_to_many :clients
end
然后我像这样从活动记录导轨指南中定义了我的连接表
class CreateClientsThemesJoinTable < ActiveRecord::Migration
def change
create_table :clients_xy_themes, id: false do |t|
t.integer :client_id
t.integer :xy_theme_id
end
add_index :clients_xy_themes, :client_id
add_index :clients_xy_themes, :xy_theme_id
end
end
但是当我尝试从 rails 控制台中的客户端表访问主题时,我得到了这个错误
PG::UndefinedColumn: ERROR: column clients_xy_themes.theme_id does not exist
LINE 1: ...ER JOIN "clients_xy_themes" ON "xy_themes"."id" = "clients_v...
为什么会这样?我的迁移特别说明了主题表上的键,但它试图访问一个不存在的列
【问题讨论】:
标签: ruby-on-rails