forest_admin_datasource_active_record 1.0.0.pre.beta.60 → 1.0.0.pre.beta.61

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: 06eb4e50d70ed020e78c247129d24f1a514efcc8e3150864ac00e2a420d715ed
4
- data.tar.gz: e11b2afab09fbf5ac3e9555a288f70638e2c01e5d2135a983b8601324d701916
3
+ metadata.gz: c9ce7a6a32ae3e985c64e2c9458165de5d24e8d7a532ca6a405aac048ef5ede8
4
+ data.tar.gz: 65ba39d8d70775cbb98e4b0f0d85888a5946fda8e34bd88bb8e7e3b52004fe2c
5
5
  SHA512:
6
- metadata.gz: 895ce913914b2400d39f09b197ef29e25524bcd524e75749a206cb5be6797665f026eac1ab0f99bceff4b11d9546c56edd3e92155c90a68434705faba6b411ec
7
- data.tar.gz: 5afa4e3d45800cce7d9f1a274eba8ccaf78d5c473460e1ccc56dada1064319d7e5d4b1a81b53ccadf293a64f61a1d607021665c6fdee7d95f1f143af4051d29f
6
+ metadata.gz: 2a1fcf17fd734b4275c86f82ac5afb4ff03bb4ac5a52b556b2df3ef1407f38076b37c94d650923711e0fe56fb63455e80ad1713c403592a93501b54e088b595b
7
+ data.tar.gz: 112af29e8fab7793768607f64e5f51c97183623cf461f8fcd24f332267d40d5bb62b04e2cc73115e2c0b7f10f239a1d97cc82023cf09646d78de40c5c0cfaff2
@@ -30,7 +30,7 @@ module ForestAdminDatasourceActiveRecord
30
30
  end
31
31
 
32
32
  def create(_caller, data)
33
- Utils::ActiveRecordSerializer.new(@model.create(data)).to_hash
33
+ Utils::ActiveRecordSerializer.new(@model.create(data)).to_hash(ProjectionFactory.all(self))
34
34
  end
35
35
 
36
36
  def update(_caller, filter, data)
@@ -63,49 +63,75 @@ module ForestAdminDatasourceActiveRecord
63
63
  end
64
64
  end
65
65
 
66
+ def association_primary_key?(association)
67
+ !association.association_primary_key.empty?
68
+ rescue StandardError
69
+ false
70
+ end
71
+
66
72
  def fetch_associations
67
73
  associations(@model).each do |association|
68
74
  case association.macro
69
75
  when :has_one
70
- add_field(
71
- association.name.to_s,
72
- ForestAdminDatasourceToolkit::Schema::Relations::OneToOneSchema.new(
73
- foreign_collection: association.class_name.demodulize.underscore,
74
- origin_key: association.foreign_key,
75
- origin_key_target: association.association_primary_key
76
- )
77
- )
76
+ if association_primary_key?(association)
77
+ if association.through_reflection?
78
+ add_field(
79
+ association.name.to_s,
80
+ ForestAdminDatasourceToolkit::Schema::Relations::ManyToManySchema.new(
81
+ foreign_collection: association.class_name.demodulize.underscore,
82
+ origin_key: association.through_reflection.foreign_key,
83
+ origin_key_target: association.through_reflection.join_foreign_key,
84
+ foreign_key: association.join_foreign_key,
85
+ foreign_key_target: association.association_primary_key,
86
+ through_collection: association.through_reflection.class_name.demodulize.underscore
87
+ )
88
+ )
89
+ else
90
+ add_field(
91
+ association.name.to_s,
92
+ ForestAdminDatasourceToolkit::Schema::Relations::OneToOneSchema.new(
93
+ foreign_collection: association.class_name.demodulize.underscore,
94
+ origin_key: association.foreign_key,
95
+ origin_key_target: association.association_primary_key
96
+ )
97
+ )
98
+ end
99
+ end
78
100
  when :belongs_to
79
- add_field(
80
- association.name.to_s,
81
- ForestAdminDatasourceToolkit::Schema::Relations::ManyToOneSchema.new(
82
- foreign_collection: association.class_name.demodulize.underscore,
83
- foreign_key: association.foreign_key,
84
- foreign_key_target: association.association_primary_key
85
- )
86
- )
87
- when :has_many
88
- if association.through_reflection?
101
+ if association_primary_key?(association)
89
102
  add_field(
90
103
  association.name.to_s,
91
- ForestAdminDatasourceToolkit::Schema::Relations::ManyToManySchema.new(
104
+ ForestAdminDatasourceToolkit::Schema::Relations::ManyToOneSchema.new(
92
105
  foreign_collection: association.class_name.demodulize.underscore,
93
- origin_key: association.through_reflection.foreign_key,
94
- origin_key_target: association.through_reflection.join_foreign_key,
95
- foreign_key: association.join_foreign_key,
96
- foreign_key_target: association.association_primary_key,
97
- through_collection: association.through_reflection.class_name.demodulize.underscore
106
+ foreign_key: association.foreign_key,
107
+ foreign_key_target: association.association_primary_key
98
108
  )
99
109
  )
100
- else
101
- add_field(
102
- association.name.to_s,
103
- ForestAdminDatasourceToolkit::Schema::Relations::OneToManySchema.new(
104
- foreign_collection: association.class_name.demodulize.underscore,
105
- origin_key: association.foreign_key,
106
- origin_key_target: association.association_primary_key
110
+ end
111
+ when :has_many
112
+ if association_primary_key?(association)
113
+ if association.through_reflection?
114
+ add_field(
115
+ association.name.to_s,
116
+ ForestAdminDatasourceToolkit::Schema::Relations::ManyToManySchema.new(
117
+ foreign_collection: association.class_name.demodulize.underscore,
118
+ origin_key: association.through_reflection.foreign_key,
119
+ origin_key_target: association.through_reflection.join_foreign_key,
120
+ foreign_key: association.join_foreign_key,
121
+ foreign_key_target: association.association_primary_key,
122
+ through_collection: association.through_reflection.class_name.demodulize.underscore
123
+ )
107
124
  )
108
- )
125
+ else
126
+ add_field(
127
+ association.name.to_s,
128
+ ForestAdminDatasourceToolkit::Schema::Relations::OneToManySchema.new(
129
+ foreign_collection: association.class_name.demodulize.underscore,
130
+ origin_key: association.foreign_key,
131
+ origin_key_target: association.association_primary_key
132
+ )
133
+ )
134
+ end
109
135
  end
110
136
  end
111
137
  end
@@ -19,11 +19,20 @@ module ForestAdminDatasourceActiveRecord
19
19
  end
20
20
  end
21
21
 
22
+ def primary_key?(model)
23
+ !model.primary_key.empty?
24
+ rescue StandardError
25
+ false
26
+ end
27
+
22
28
  def fetch_model(model)
23
29
  if model.name.start_with?('HABTM_')
24
30
  build_habtm(model)
25
31
  else
26
- @models << model unless model.abstract_class? || @models.include?(model) || !model.table_exists?
32
+ @models << model unless model.abstract_class? ||
33
+ @models.include?(model) ||
34
+ !model.table_exists? ||
35
+ !primary_key?(model)
27
36
  end
28
37
  end
29
38
 
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceActiveRecord
2
- VERSION = "1.0.0-beta.60"
2
+ VERSION = "1.0.0-beta.61"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_datasource_active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.60
4
+ version: 1.0.0.pre.beta.61
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-07-08 00:00:00.000000000 Z
12
+ date: 2024-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord