rare_map 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,16 +47,18 @@ module RareMap
47
47
  end
48
48
 
49
49
  models.each do |model|
50
- group_models = models.select { |m| m.group == model.group && m.default_id == model.default_id }
51
-
52
50
  model.relations.each do |rel_from|
53
51
  model.relations.each do |rel_to|
54
52
  if rel_from != rel_to &&
55
53
  rel_from.type == :belongs_to &&
56
54
  rel_to.type == :belongs_to &&
57
55
  rel_from.table != rel_to.table
58
- model_from = models.find { |m| m.table.name == rel_from.table }
59
- model_to = models.find { |m| m.table.name == rel_to.table }
56
+ model_from = models.find { |m| m.table.name == rel_from.table &&
57
+ m.group == model.group &&
58
+ m.default_id == model.default_id }
59
+ model_to = models.find { |m| m.table.name == rel_to.table &&
60
+ m.group == model.group &&
61
+ m.default_id == model.default_id }
60
62
  model_from.relations << Relation.new(:has_many_through, rel_to.foreign_key, model_to.table.name, model.table.name)
61
63
  model_to.relations << Relation.new(:has_many_through, rel_from.foreign_key, model_from.table.name, model.table.name)
62
64
  end
@@ -19,28 +19,28 @@ module RareMap
19
19
  belongs_to = model.relations.select { |rel| rel.type == :belongs_to }
20
20
  unless belongs_to.empty?
21
21
  output << belongs_to.
22
- map { |rel| " belongs_to :#{rel.table.pluralize.singularize}, :foreign_key => '#{rel.foreign_key}', :class_name => '#{classify_by_table(rel.table, models)}'" }.
22
+ map { |rel| " belongs_to :#{rel.table.pluralize.singularize}, :foreign_key => '#{rel.foreign_key}', :class_name => '#{classify_by_table(rel.table, model, models)}'" }.
23
23
  join("\n") << "\n"
24
24
  end
25
25
 
26
26
  has_one = model.relations.select { |rel| rel.type == :has_one }
27
27
  unless has_one.empty?
28
28
  output << has_one.
29
- map { |rel| " has_one :#{rel.table.pluralize.singularize}, :foreign_key => '#{rel.foreign_key}', :class_name => '#{classify_by_table(rel.table, models)}'" }.
29
+ map { |rel| " has_one :#{rel.table.pluralize.singularize}, :foreign_key => '#{rel.foreign_key}', :class_name => '#{classify_by_table(rel.table, model, models)}'" }.
30
30
  join("\n") << "\n"
31
31
  end
32
32
 
33
33
  has_many = model.relations.select { |rel| rel.type == :has_many }
34
34
  unless has_many.empty?
35
35
  output << has_many.
36
- map { |rel| " has_many :#{rel.table.pluralize}, :foreign_key => '#{rel.foreign_key}', :class_name => '#{classify_by_table(rel.table, models)}'" }.
36
+ map { |rel| " has_many :#{rel.table.pluralize}, :foreign_key => '#{rel.foreign_key}', :class_name => '#{classify_by_table(rel.table, model, models)}'" }.
37
37
  join("\n") << "\n"
38
38
  end
39
39
 
40
40
  has_many_through = model.relations.select { |rel| rel.type == :has_many_through }
41
41
  unless has_many_through.empty?
42
42
  output << has_many_through.
43
- map { |rel| " has_many :#{rel.table.pluralize}#{"_by_#{rel.through}, :source => :#{rel.table.pluralize.singularize}" if has_many_through.count { |hmt| hmt.table == rel.table } > 1}, :through => :#{rel.through.pluralize}, :foreign_key => '#{rel.foreign_key}', :class_name => '#{classify_by_table(rel.table, models)}'" }.
43
+ map { |rel| " has_many :#{rel.table.pluralize}#{"_by_#{rel.through}, :source => :#{rel.table.pluralize.singularize}" if has_many_through.count { |hmt| hmt.table == rel.table } > 1}, :through => :#{rel.through.pluralize}, :foreign_key => '#{rel.foreign_key}', :class_name => '#{classify_by_table(rel.table, model, models)}'" }.
44
44
  join("\n") << "\n"
45
45
  end
46
46
 
@@ -58,8 +58,10 @@ module RareMap
58
58
  end
59
59
 
60
60
  private
61
- def classify_by_table(table, models)
62
- model = models.find { |m| m.table.name == table }
61
+ def classify_by_table(table, model, models)
62
+ model = models.find { |m| m.table.name == table &&
63
+ m.group == model.group &&
64
+ m.default_id == model.default_id }
63
65
  model.classify
64
66
  end
65
67
  end
@@ -2,7 +2,7 @@ class RareMap
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- PATCH = 0
5
+ PATCH = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rare_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
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: 2012-11-30 00:00:00.000000000 Z
12
+ date: 2012-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: 4278626048823483051
145
+ hash: -750417326408919851
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  none: false
148
148
  requirements: