我正在做一个数据库:轨道未定义的方法“的has_many”
class CreateUsers < ActiveRecord::Migration
def change
has_many :listings, :dependent => :restrict #won't delete if listings exist
has_many :transactions, :dependent => :restrict #won't del if trans exist
create_table :users do |t|
t.integer :key #it's hard to use string as primary
t.string :identifier_url
t.string :username
t.integer :rating
t.timestamps
end
end
end
和
class CreateListings < ActiveRecord::Migration
def change
has_one :book
belongs_to :transaction
belongs_to :user
create_table :listings do |t|
t.integer :key
t.integer :condition
t.decimal :price
t.timestamps
end
end
end
我不能在这个地方找到任何东西,所以我猜测它的东西很基本的。
但对于使用“belongs_to的:用户“,在表格中必须有一列user_id?!? – Klaus
@克劳斯,当然可以。如果您使用生成器来创建该列的模型已经在您那里 – TopperH