提交 f5ddf817 编写于 作者: R Ryuta Kamizono

Exercise HABTM fixtures with foreign key constraints

上级 ad3669ee
......@@ -20,6 +20,12 @@ def cancel_save_callback_method
def increment_updated_count
self.updated_count += 1
end
def self.delete_all(*)
connection.delete("DELETE FROM parrots_pirates")
connection.delete("DELETE FROM parrots_treasures")
super
end
end
class LiveParrot < Parrot
......
......@@ -601,33 +601,55 @@
t.integer :non_poly_two_id
end
create_table :parrots, force: true do |t|
t.column :name, :string
t.column :color, :string
t.column :parrot_sti_class, :string
t.column :killer_id, :integer
t.column :updated_count, :integer, default: 0
if subsecond_precision_supported?
t.column :created_at, :datetime, precision: 0
t.column :created_on, :datetime, precision: 0
t.column :updated_at, :datetime, precision: 0
t.column :updated_on, :datetime, precision: 0
else
t.column :created_at, :datetime
t.column :created_on, :datetime
t.column :updated_at, :datetime
t.column :updated_on, :datetime
disable_referential_integrity do
create_table :parrots, force: :cascade do |t|
t.string :name
t.string :color
t.string :parrot_sti_class
t.integer :killer_id
t.integer :updated_count, :integer, default: 0
if subsecond_precision_supported?
t.datetime :created_at, precision: 0
t.datetime :created_on, precision: 0
t.datetime :updated_at, precision: 0
t.datetime :updated_on, precision: 0
else
t.datetime :created_at
t.datetime :created_on
t.datetime :updated_at
t.datetime :updated_on
end
end
end
create_table :parrots_pirates, id: false, force: true do |t|
t.column :parrot_id, :integer
t.column :pirate_id, :integer
end
create_table :pirates, force: :cascade do |t|
t.string :catchphrase
t.integer :parrot_id
t.integer :non_validated_parrot_id
if subsecond_precision_supported?
t.datetime :created_on, precision: 6
t.datetime :updated_on, precision: 6
else
t.datetime :created_on
t.datetime :updated_on
end
end
create_table :parrots_treasures, id: false, force: true do |t|
t.column :parrot_id, :integer
t.column :treasure_id, :integer
create_table :treasures, force: :cascade do |t|
t.string :name
t.string :type
t.references :looter, polymorphic: true
t.references :ship
end
create_table :parrots_pirates, id: false, force: true do |t|
t.references :parrot, foreign_key: true
t.references :pirate, foreign_key: true
end
create_table :parrots_treasures, id: false, force: true do |t|
t.references :parrot, foreign_key: true
t.references :treasure, foreign_key: true
end
end
create_table :people, force: true do |t|
......@@ -673,19 +695,6 @@
t.column :rainbow_color, :string
end
create_table :pirates, force: true do |t|
t.column :catchphrase, :string
t.column :parrot_id, :integer
t.integer :non_validated_parrot_id
if subsecond_precision_supported?
t.column :created_on, :datetime, precision: 6
t.column :updated_on, :datetime, precision: 6
else
t.column :created_on, :datetime
t.column :updated_on, :datetime
end
end
create_table :posts, force: true do |t|
t.references :author
t.string :title, null: false
......@@ -916,14 +925,6 @@
t.datetime :updated_at
end
create_table :treasures, force: true do |t|
t.column :name, :string
t.column :type, :string
t.column :looter_id, :integer
t.column :looter_type, :string
t.belongs_to :ship
end
create_table :tuning_pegs, force: true do |t|
t.integer :guitar_id
t.float :pitch
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册