dynamic-active-model 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c42ba085fec588cc54f0dfb2412f779a000f24844173500447b96715e5b4d824
4
- data.tar.gz: 42650ca61f8c7a6748df8ebc77dfd0cc080ac7c53966e6f38c22720b41812d42
3
+ metadata.gz: 73b173018e9af4d94db62bf921d964015577605528495c893e7d905b735d11ab
4
+ data.tar.gz: e83792d3d00058247a4f7e7ed9c8676f0166e2cb6ebc8675cbf4c8badd58be76
5
5
  SHA512:
6
- metadata.gz: 6feba211353f6825a46de00879d7d0fe10eebd69f3bbbd2d97380cdde303ea5b7c09cf39cfaf3757d08a6853ed9895c96a3f52bd58d69da330020a42b566ffd5
7
- data.tar.gz: 5fa1bb1f1486b3619d8142b490a2e11226e30e3a795ae4df2bd6d65a649a460282ebfe6fd56f4532bd479457dc8c67225779b3cbd0522cb5d0974cb7211efb90
6
+ metadata.gz: 5d1058ca2a6cad412c32367a695641b57e6be67979cd337c2d83e91a994cf5b4048dc5ca3f709eac7f39d1e63632e175a4fb1348467cb885cec90badc8452f48
7
+ data.tar.gz: 3180c4951dfbd32e5cc1dd398306b7dec0844b4e82d47495b3b97776ebac3794636bb64cc9c87db5994d9e157e5b4c4fa785e99636e1548773a624d7687904b2
@@ -25,10 +25,10 @@ module DynamicActiveModel
25
25
  model.column_names.each do |column_name|
26
26
  next unless foreign_key_to_models[column_name.downcase]
27
27
 
28
- foreign_key_to_models[column_name.downcase].each do |foreign_model, relationship_name|
28
+ foreign_key_to_models[column_name.downcase].each do |foreign_model, relationship_name, additional|
29
29
  next if foreign_model == model
30
30
 
31
- add_relationships(relationship_name, model, foreign_model, column_name)
31
+ add_relationships(relationship_name, model, foreign_model, column_name, additional)
32
32
  end
33
33
  end
34
34
  end
@@ -36,9 +36,14 @@ module DynamicActiveModel
36
36
 
37
37
  private
38
38
 
39
- def add_relationships(relationship_name, model, belongs_to_model, foreign_key)
39
+ def add_relationships(relationship_name, model, belongs_to_model, foreign_key, additional)
40
40
  add_belongs_to(relationship_name, model, belongs_to_model, foreign_key)
41
- add_has_many(belongs_to_model, model, foreign_key)
41
+ add_has_many(
42
+ additional ? relationship_name : nil,
43
+ belongs_to_model,
44
+ model,
45
+ foreign_key
46
+ )
42
47
  end
43
48
 
44
49
  def add_belongs_to(relationship_name, model, belongs_to_model, foreign_key)
@@ -50,9 +55,11 @@ module DynamicActiveModel
50
55
  )
51
56
  end
52
57
 
53
- def add_has_many(model, has_many_model, foreign_key)
58
+ def add_has_many(relationship_name, model, has_many_model, foreign_key)
59
+ relationship_name = relationship_name ? (relationship_name + '_') : ''
60
+ relationship_name += has_many_model.table_name
54
61
  model.has_many(
55
- has_many_model.table_name.underscore.pluralize.to_sym,
62
+ relationship_name.underscore.pluralize.to_sym,
56
63
  class_name: has_many_model.name,
57
64
  foreign_key: foreign_key,
58
65
  primary_key: has_many_model.primary_key
@@ -61,9 +68,11 @@ module DynamicActiveModel
61
68
 
62
69
  def create_foreign_key_to_model_map
63
70
  @foreign_keys.values.each_with_object({}) do |foreign_key, hsh|
71
+ additional = false
64
72
  foreign_key.keys.each do |key, relationship_name|
65
73
  hsh[key.downcase] ||= []
66
- hsh[key.downcase] << [foreign_key.model, relationship_name]
74
+ hsh[key.downcase] << [foreign_key.model, relationship_name, additional]
75
+ additional = true
67
76
  end
68
77
  end
69
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic-active-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-13 00:00:00.000000000 Z
11
+ date: 2019-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord