spec/spec_helper.rb in ar-simple-idmap-0.2.4 vs spec/spec_helper.rb in ar-simple-idmap-0.3.0
- old
+ new
@@ -29,12 +29,22 @@
t.string :name
t.integer :value, :default=>1
end
create_table :phone_numbers, :force => true do |t|
t.string :number
- t.integer :customer_id
+ t.references :customer
end
+ create_table :buildings, :force => true do |t|
+ t.string :name
+ end
+ create_table :addresses, :force => true do |t|
+ t.string :name
+ end
+ create_table :addresses_buildings, :force => true, :id => false do |t|
+ t.references :building
+ t.references :address
+ end
end
class Customer < ActiveRecord::Base
use_id_map
has_many :phone_numbers
@@ -47,5 +57,21 @@
belongs_to :customer
end
phone_number = customer.phone_numbers.create(:number => "8675309")
+class Building < ActiveRecord::Base
+ use_id_map
+ has_and_belongs_to_many :addresses
+end
+
+building = Building.create(:name => 'GoOne')
+
+class Address < ActiveRecord::Base
+ use_id_map
+ has_and_belongs_to_many :customers
+end
+
+address1 = Address.create(:name=>'volga')
+address2 = Address.create(:name=>'don')
+building.addresses << address1
+building.addresses << address2