Hi there... sorry if this is a double post. I tried posting this
earlier and can't see the listing for it.
I've created the following model files...
class Cartclass < ActiveRecord::Base
belongs_to :product
end
class Carttype < ActiveRecord::Base
belongs_to :product
end
class Manufacturer < ActiveRecord::Base
belongs_to :product
end
class Product < ActiveRecord::Base
has_one :manufacturer
has_one :carttype
has_one :cartclass
end
... and added the following migration script....
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.column :name, :string
t.column :carttype_id, :integer
t.column :cartclass_id, :integer
t.column :manufacturer_id, :integer
t.column :shortnum, :string
t.column :partnumber, :string
t.column :boxnumber, :string
t.column :stock, :string
t.column :colour, :string
end
end
def self.down
drop_table :products
end
end
... but when I try running rake db:migrate, it seems to completely skip
over this without creating a table. No error messages or anything.
Am I missing something?
Thanks,
Brandon
>
Hey
Make sure that the migration file's prefix number is smaller than the
value in your schema_info table in your database. Rails uses this number
to determine which migrations are yet to be run. This assumes you've ran
migrations before, if you haven't you won't have a schema_info table and
I have no idea what the problem may be
Also, I notice that your belongs_to statements are in your Carttype,
Cartclass and Manufacturer models, but you're creating the foreign keys
in your products table. AFAIK, foreign keys go in the table
corresponding to the belongs_to statement (as with has_many and belongs_to).
Also, I notice that your belongs_to statements are in your Carttype,
Cartclass and Manufacturer models, but you’re creating the foreign keys
in your products table. AFAIK, foreign keys go in the table
corresponding to the belongs_to statement (as with has_many and belongs_to).
Cheery-o
Paul, Gustav
Thanks very much, I’ll take a look at that later today.
Why does that seem counter-intuitive? If my cartclass, carttype and manufacturer tables are lookup items for a product, I would consider them children of the product, normally… wouldn’t it make sense for these child items to belong to the parent?