rare_map 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rare_map/model_builder.rb +7 -2
- data/lib/rare_map/schema_parser.rb +11 -6
- data/lib/rare_map/version.rb +2 -2
- metadata +3 -3
@@ -31,13 +31,18 @@ module RareMap
|
|
31
31
|
models.each do |model|
|
32
32
|
group_models = models.select { |m| m.group == model.group && m.default_id == model.default_id }
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
group_models.each do |gm|
|
35
|
+
model.table.columns.each do |col|
|
36
36
|
if gm.table.match_foreign_key(col) && model != gm
|
37
37
|
model.relations << Relation.new(:belongs_to, col.name, gm.table.name)
|
38
38
|
gm.relations << Relation.new(col.unique? ? :has_one : :has_many, col.name, model.table.name)
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
if gm.table.match_foreign_key_by_primary_key(model.table.primary_key) && model != gm
|
43
|
+
model.relations << Relation.new(:belongs_to, model.table.primary_key, gm.table.name)
|
44
|
+
gm.relations << Relation.new(:has_one, model.table.primary_key, model.table.name)
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
@@ -63,15 +63,20 @@ module RareMap
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def match_foreign_key(column)
|
66
|
-
if column.references == @name ||
|
67
|
-
"#{@name}#{fk_suffix}",
|
68
|
-
"#{singularize}_#{fk_suffix}",
|
69
|
-
"#{singularize}#{fk_suffix}",
|
70
|
-
"#{pluralize}_#{fk_suffix}",
|
71
|
-
"#{pluralize}#{fk_suffix}"].include?(column.name)
|
66
|
+
if column.references == @name || foreign_keys.include?(column.name)
|
72
67
|
@name if primary_key
|
73
68
|
end
|
74
69
|
end
|
70
|
+
|
71
|
+
def match_foreign_key_by_primary_key(pk)
|
72
|
+
@name if foreign_keys.include?(pk) && primary_key
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
def foreign_keys
|
77
|
+
["#{@name}_#{fk_suffix}", "#{@name}#{fk_suffix}", "#{singularize}_#{fk_suffix}",
|
78
|
+
"#{singularize}#{fk_suffix}", "#{pluralize}_#{fk_suffix}", "#{pluralize}#{fk_suffix}"]
|
79
|
+
end
|
75
80
|
end
|
76
81
|
|
77
82
|
class Column
|
data/lib/rare_map/version.rb
CHANGED
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.0
|
4
|
+
version: 1.1.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: 2012-11-
|
12
|
+
date: 2012-11-30 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:
|
145
|
+
hash: 4278626048823483051
|
146
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
147
|
none: false
|
148
148
|
requirements:
|