immigrant 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,9 @@
1
1
  module Immigrant
2
2
  # add some useful stuff to foreigner's ForeignKeyDefinition
3
- # TODO: get it in foreigner so we don't need to monkey patch
3
+ # TODO: get more of this into foreigner so we don't need to monkey patch
4
4
  module ForeignKeyDefinition
5
+ include Foreigner::SchemaDumper::ClassMethods
6
+
5
7
  def initialize(from_table, to_table, options, *args)
6
8
  options ||= {}
7
9
  options[:name] ||= "#{from_table}_#{options[:column]}_fk"
@@ -14,21 +16,7 @@ module Immigrant
14
16
 
15
17
  def to_ruby(action = :add)
16
18
  if action == :add
17
- # not DRY ... guts of this are copied from Foreigner :(
18
- parts = [ ('add_foreign_key ' + from_table.inspect) ]
19
- parts << to_table.inspect
20
- parts << (':name => ' + options[:name].inspect)
21
-
22
- if options[:column] != "#{to_table.singularize}_id"
23
- parts << (':column => ' + options[:column].inspect)
24
- end
25
- if options[:primary_key] != 'id'
26
- parts << (':primary_key => ' + options[:primary_key].inspect)
27
- end
28
- if options[:dependent].present?
29
- parts << (':dependent => ' + options[:dependent].inspect)
30
- end
31
- parts.join(', ')
19
+ dump_foreign_key(self)
32
20
  else
33
21
  "remove_foreign_key #{from_table.inspect}, " \
34
22
  ":name => #{options[:name].inspect}"
data/lib/immigrant.rb CHANGED
@@ -69,6 +69,7 @@ module Immigrant
69
69
  # Foo.has_many :bazzes, :class_name => Bar
70
70
  # we need to make sure everything is legit and see if any of them
71
71
  # specify :dependent => :delete
72
+ next if foreign_key.nil?
72
73
  if current_key = foreign_keys[foreign_key.hash_key]
73
74
  if current_key.to_table != foreign_key.to_table || current_key.options[:primary_key] != foreign_key.options[:primary_key]
74
75
  warnings[foreign_key.hash_key] ||= "Skipping #{foreign_key.from_table}.#{foreign_key.options[:column]}: it has multiple associations referencing different keys/tables."
@@ -138,4 +139,4 @@ module Immigrant
138
139
  end
139
140
 
140
141
  require 'immigrant/loader'
141
- require 'immigrant/railtie' if defined?(Rails)
142
+ require 'immigrant/railtie' if defined?(Rails)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immigrant
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jon Jensen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-04-01 00:00:00 -06:00
18
+ date: 2012-05-28 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -41,12 +41,12 @@ dependencies:
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- hash: 21
44
+ hash: 31
45
45
  segments:
46
46
  - 1
47
47
  - 1
48
- - 3
49
- version: 1.1.3
48
+ - 6
49
+ version: 1.1.6
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  description: Adds a generator for creating a foreign key migration based on your current model associations