foreigner 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -74,9 +74,10 @@ Remove an unwanted foreign key:
74
74
  t.remove_foreign_key :users
75
75
  end
76
76
 
77
- == Finding Missing Foreign Keys
77
+ == Foreigner Add-ons
78
78
 
79
- Use {Immigrant}[https://github.com/jenseng/immigrant] to generate a migration that includes all missing foreign keys.
79
+ * {immigrant}[https://github.com/jenseng/immigrant] - generate a migration that includes all missing foreign keys.
80
+ * {sqlserver-foreigner}[https://github.com/cleblanc87/sqlserver-foreigner] - A plugin for SQL Server.
80
81
 
81
82
  == License
82
83
 
@@ -15,7 +15,11 @@ module Foreigner
15
15
  definition = td # This is my trick to get the definition
16
16
  block.call(td)
17
17
  end
18
- definition.foreign_keys.each { |c,o| add_foreign_key table_name, c, o }
18
+ definition.foreign_keys.each do |to_table, options_list|
19
+ options_list.each do |options|
20
+ add_foreign_key(table_name, to_table, options)
21
+ end
22
+ end
19
23
  end
20
24
 
21
25
  def supports_foreign_keys?
@@ -2,7 +2,8 @@ module Foreigner
2
2
  module ConnectionAdapters
3
3
  module TableDefinition
4
4
  def foreign_key(to_table, options = {})
5
- foreign_keys[to_table] = options
5
+ foreign_keys[to_table] ||= []
6
+ foreign_keys[to_table] << options
6
7
  end
7
8
 
8
9
  def foreign_keys
@@ -5,9 +5,17 @@ class Foreigner::ConnectionAdapters::TableDefinitionsTest < ActiveSupport::TestC
5
5
  include Foreigner::ConnectionAdapters::TableDefinition
6
6
  end
7
7
 
8
- test "foreign_key" do
8
+ test "foreign_key used once" do
9
9
  definition = TestDefinition.new
10
10
  definition.foreign_key :poops, and: :one;
11
- assert_equal definition.foreign_keys[:poops], and: :one
11
+ assert_equal [{ and: :one }], definition.foreign_keys[:poops]
12
+ end
13
+
14
+ test "foreign_key used twice" do
15
+ definition = TestDefinition.new
16
+ definition.foreign_key :nodes, column: :from_id
17
+ definition.foreign_key :nodes, column: :to_id
18
+ assert_equal [{ column: :from_id }, { column: :to_id }],
19
+ definition.foreign_keys[:nodes]
12
20
  end
13
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreigner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-15 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord