Browse files

Associations may now be added inside a repository do ... end block

  • Loading branch information...
1 parent 4b63dcb commit c5bbdd0ac554932d09903b03a38a063ceda1c522 @david david committed Apr 18, 2008
View
2 lib/data_mapper/associations/many_to_one.rb
@@ -13,7 +13,7 @@ def many_to_one(name, options = {})
relationships[name] = Relationship.new(
name,
- options[:repository_name] || repository.name,
+ repository.name,
child_model_name,
nil,
parent_model_name,
View
2 lib/data_mapper/associations/one_to_many.rb
@@ -15,7 +15,7 @@ def one_to_many(name, options = {})
relationships[name] = Relationship.new(
DataMapper::Inflection.underscore(parent_model_name).to_sym,
- options[:repository_name] || repository.name,
+ repository.name,
child_model_name,
nil,
parent_model_name,
View
2 lib/data_mapper/associations/one_to_one.rb
@@ -12,7 +12,7 @@ def one_to_one(name, options = {})
relationships[name] = Relationship.new(
DataMapper::Inflection.underscore(parent_model_name).to_sym,
- options[:repository_name] || repository.name,
+ repository.name,
child_model_name,
nil,
parent_model_name,
View
41 spec/integration/association_spec.rb
@@ -21,7 +21,9 @@ class Yard
property :id, Fixnum, :serial => true
property :name, String
- many_to_one :engine, :repository_name => :sqlite3
+ repository(:sqlite3) do
+ many_to_one :engine
+ end
end
class Pie
@@ -37,7 +39,9 @@ class Sky
property :id, Fixnum, :serial => true
property :name, String
- one_to_one :pie, :repository_name => :sqlite3
+ repository(:sqlite3) do
+ one_to_one :pie
+ end
end
class Host
@@ -46,7 +50,9 @@ class Host
property :id, Fixnum, :serial => true
property :name, String
- one_to_many :slices, :repository_name => :sqlite3
+ repository(:sqlite3) do
+ one_to_many :slices
+ end
end
class Slice
@@ -55,7 +61,9 @@ class Slice
property :id, Fixnum, :serial => true
property :name, String
- many_to_one :host, :repository_name => :sqlite3
+ repository(:sqlite3) do
+ many_to_one :host, :repository_name => :sqlite3
+ end
end
describe DataMapper::Associations do
@@ -282,6 +290,31 @@ class Slice
s.host.id.should == 10
end
+ # describe '#through' do
+ # before(:all) do
+ # class Cake
+ # property :id, Fixnum, :serial => true
+ # property :name, String
+ # has :slices, 1..n
+ # end
+ #
+ # @adapter.execute(<<-EOS.compress_lines)
+ # CREATE TABLE "cakes" (
+ # "id" INTEGER PRIMARY KEY,
+ # "name" VARCHAR(50)
+ # )
+ # EOS
+ #
+ # @adapter.execute('INSERT INTO "cakes" ("id", "name") values (?, ?)', 1, 'cake1', 1)
+ # @adapter.execute('INSERT INTO "cakes" ("id", "name") values (?, ?)', 2, 'cake2', 1)
+ #
+ # class Slice
+ # has :cake, n..1
+ # end
+ # end
+ #
+ # end
+
after do
@adapter.execute('DROP TABLE "slices"')
@adapter.execute('DROP TABLE "hosts"')

0 comments on commit c5bbdd0

Please sign in to comment.