Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #101 from bluemont/issue-100

Issue 100
  • Loading branch information...
commit cda87b4473dc187a54a9a0335ee4590e74b42bfb 2 parents e8186e7 + fcfc684
@matthuhiggins authored
View
6 lib/foreigner/connection_adapters/abstract/schema_statements.rb
@@ -15,7 +15,11 @@ def create_table(table_name, *args, &block)
definition = td # This is my trick to get the definition
block.call(td)
end
- definition.foreign_keys.each { |c,o| add_foreign_key table_name, c, o }
+ definition.foreign_keys.each do |to_table, options_list|
+ options_list.each do |options|
+ add_foreign_key(table_name, to_table, options)
+ end
+ end
end
def supports_foreign_keys?
View
3  lib/foreigner/connection_adapters/abstract/table_definition.rb
@@ -2,7 +2,8 @@ module Foreigner
module ConnectionAdapters
module TableDefinition
def foreign_key(to_table, options = {})
- foreign_keys[to_table] = options
+ foreign_keys[to_table] ||= []
+ foreign_keys[to_table] << options
end
def foreign_keys
View
12 test/foreigner/connection_adapters/abstract/table_definition_test.rb
@@ -5,9 +5,17 @@ class TestDefinition
include Foreigner::ConnectionAdapters::TableDefinition
end
- test "foreign_key" do
+ test "foreign_key used once" do
definition = TestDefinition.new
definition.foreign_key :poops, and: :one;
- assert_equal definition.foreign_keys[:poops], and: :one
+ assert_equal [{ and: :one }], definition.foreign_keys[:poops]
+ end
+
+ test "foreign_key used twice" do
+ definition = TestDefinition.new
+ definition.foreign_key :nodes, column: :from_id
+ definition.foreign_key :nodes, column: :to_id
+ assert_equal [{ column: :from_id }, { column: :to_id }],
+ definition.foreign_keys[:nodes]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.