forest_admin_datasource_active_record 1.0.0.pre.beta.52 → 1.0.0.pre.beta.54
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/forest_admin_datasource_active_record/collection.rb +5 -2
- data/lib/forest_admin_datasource_active_record/datasource.rb +43 -1
- data/lib/forest_admin_datasource_active_record/utils/query.rb +2 -4
- data/lib/forest_admin_datasource_active_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 872ac653d0f9a281cab0421a9f01343ab3ee751ab12dd89d07aaabc870ecd91e
|
4
|
+
data.tar.gz: dc666fc765acabfa4ce22fccd2e3240f4c4ba308884d2b77754b6ffd33adf85d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 613b29a6e6f7119ecc1d33f2955b5bf3fdf69999a4d6a2d7066c1a423b4bff4af630dc8dd4aefdf2fdc88a4f2393da8dcb5edc379ab54f89ba00e00ab158c512
|
7
|
+
data.tar.gz: fc7ca9cc8868bdf8aca89735d1c22c550bdb45b962054958dd1cc8c01a2cd0ec8022c67dd27c1e7ea3c5c05f51442cbd7d8f22ff6e417eefd5352c667296dcb2
|
@@ -15,6 +15,10 @@ module ForestAdminDatasourceActiveRecord
|
|
15
15
|
enable_count
|
16
16
|
end
|
17
17
|
|
18
|
+
def native_driver
|
19
|
+
ActiveRecord::Base.connection
|
20
|
+
end
|
21
|
+
|
18
22
|
def list(_caller, filter, projection)
|
19
23
|
query = Utils::Query.new(self, projection, filter)
|
20
24
|
|
@@ -43,11 +47,10 @@ module ForestAdminDatasourceActiveRecord
|
|
43
47
|
|
44
48
|
def fetch_fields
|
45
49
|
@model.columns_hash.each do |column_name, column|
|
46
|
-
# TODO: check is not sti column
|
47
50
|
field = ForestAdminDatasourceToolkit::Schema::ColumnSchema.new(
|
48
51
|
column_type: get_column_type(@model, column),
|
49
52
|
filter_operators: operators_for_column_type(get_column_type(@model, column)),
|
50
|
-
is_primary_key: column_name == @model.primary_key,
|
53
|
+
is_primary_key: column_name == @model.primary_key || @model.primary_key.include?(column_name),
|
51
54
|
is_read_only: false,
|
52
55
|
is_sortable: true,
|
53
56
|
default_value: column.default,
|
@@ -5,6 +5,7 @@ module ForestAdminDatasourceActiveRecord
|
|
5
5
|
def initialize(db_config = {})
|
6
6
|
super()
|
7
7
|
@models = []
|
8
|
+
@habtm_models = {}
|
8
9
|
init_orm(db_config)
|
9
10
|
generate
|
10
11
|
end
|
@@ -19,11 +20,52 @@ module ForestAdminDatasourceActiveRecord
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def fetch_model(model)
|
22
|
-
|
23
|
+
if model.name.start_with?('HABTM_')
|
24
|
+
build_habtm(model)
|
25
|
+
else
|
26
|
+
@models << model unless model.abstract_class? || @models.include?(model) || !model.table_exists?
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
def init_orm(db_config)
|
26
31
|
ActiveRecord::Base.establish_connection(db_config)
|
27
32
|
end
|
33
|
+
|
34
|
+
def build_habtm(model)
|
35
|
+
if @habtm_models.key?(model.table_name)
|
36
|
+
@habtm_models[model.table_name].left_reflection = model.right_reflection
|
37
|
+
# when the second model is added, we can push the HABTM model to the models list
|
38
|
+
@models << make_through_model(
|
39
|
+
model.table_name,
|
40
|
+
[
|
41
|
+
@habtm_models[model.table_name].left_reflection,
|
42
|
+
@habtm_models[model.table_name].right_reflection
|
43
|
+
]
|
44
|
+
)
|
45
|
+
else
|
46
|
+
@habtm_models[model.table_name] = model
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def make_through_model(table_name, associations)
|
51
|
+
through_model = Class.new(ActiveRecord::Base) do
|
52
|
+
class << self
|
53
|
+
attr_accessor :name, :table_name
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.add_association(name, options)
|
57
|
+
belongs_to name, required: false, **options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
through_model.name = table_name.singularize
|
62
|
+
through_model.table_name = table_name
|
63
|
+
through_model.primary_key = [associations[0].foreign_key, associations[1].foreign_key]
|
64
|
+
associations.each do |association|
|
65
|
+
through_model.add_association(association.name, association.options)
|
66
|
+
end
|
67
|
+
|
68
|
+
through_model
|
69
|
+
end
|
28
70
|
end
|
29
71
|
end
|
@@ -82,7 +82,7 @@ module ForestAdminDatasourceActiveRecord
|
|
82
82
|
when Operators::LIKE
|
83
83
|
@query = @query.send(aggregator, @query.where(@arel_table[field.to_sym].matches(value)))
|
84
84
|
when Operators::INCLUDES_ALL
|
85
|
-
|
85
|
+
@query = @query.send(aggregator, @query.where(@arel_table[field.to_sym].matches_all(value)))
|
86
86
|
end
|
87
87
|
|
88
88
|
@query
|
@@ -107,9 +107,7 @@ module ForestAdminDatasourceActiveRecord
|
|
107
107
|
def apply_select
|
108
108
|
unless @projection.nil?
|
109
109
|
@query = @query.select(@select.join(', '))
|
110
|
-
@query = @query.
|
111
|
-
# TODO: replace eager_load by joins because eager_load select ALL columns of relation
|
112
|
-
# @query = @query.joins(@projection.relations.keys.map(&:to_sym))
|
110
|
+
@query = @query.joins(@projection.relations.keys.map(&:to_sym))
|
113
111
|
end
|
114
112
|
|
115
113
|
@query
|
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.
|
4
|
+
version: 1.0.0.pre.beta.54
|
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-06-
|
12
|
+
date: 2024-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|