Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mongoid datasource #111

Merged
merged 104 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from 99 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
21b42e4
feat(mongo): add datasource mongo package
nicolasalexandre9 Jan 13, 2025
5e65c54
feat(mongo): parse field validations
nicolasalexandre9 Jan 13, 2025
ae83b45
fix(validation): fix field validation parser on active record datasource
nicolasalexandre9 Jan 13, 2025
63aee33
feat(mongo): add relations
matthv Jan 14, 2025
6aa048b
fix: relation
matthv Jan 15, 2025
fcc65f8
feat(relation): handle has_and_belongs_to_many
matthv Jan 15, 2025
b4ac340
feat(mongo): add query builder
nicolasalexandre9 Jan 17, 2025
4a58016
feat(relation): handle embedded relations
matthv Jan 17, 2025
2830930
feat(mongo): add query aggregate builder
nicolasalexandre9 Jan 20, 2025
f317e5c
fix(relations): polymorphic & embedded
matthv Jan 20, 2025
7ec49ac
chore: add dummy rails app & setup spec config
matthv Jan 20, 2025
2a5a93d
chore: clean dummy rails
matthv Jan 21, 2025
1603826
chore: update log mongoid rspec
matthv Jan 21, 2025
e81e71d
fix(introspection): field is primary_key only if is not retalted to a…
nicolasalexandre9 Jan 21, 2025
e0b48c4
chore: add test
matthv Jan 22, 2025
040b7a1
fix(introspection): add embedded fields as column with composite type
nicolasalexandre9 Jan 22, 2025
86f00b5
chore: remove habtm logic
matthv Jan 22, 2025
669e8d5
chore: update config for test
matthv Jan 22, 2025
a13371c
chore: add test for datasource
matthv Jan 22, 2025
9988ee9
fix(store): fix format data and build filter
nicolasalexandre9 Jan 23, 2025
43cdf8f
fix(relation): format collection name for polyporphic type
nicolasalexandre9 Jan 23, 2025
d570a94
feat(crud): add support of create, update and delete operations
nicolasalexandre9 Jan 23, 2025
eda8aad
feat(serializer): serialize hasOne and belongsTo relations
nicolasalexandre9 Jan 23, 2025
3b82788
chore: test on collection
matthv Jan 23, 2025
45831e7
chore: add tests on parser column
matthv Jan 23, 2025
bbbe0ae
test(collection): add tests on crud methodes
nicolasalexandre9 Jan 27, 2025
a48dc18
fix: validations
matthv Jan 28, 2025
d38a920
chore: add tests on validation & column
matthv Jan 28, 2025
45d1903
feat: build query with OneToOne and ManyToOne relations
nicolasalexandre9 Jan 28, 2025
32981c5
chore: add tests for relation parser
matthv Jan 28, 2025
3281ade
test(serializer): add tests on mongoid serializer
nicolasalexandre9 Jan 28, 2025
5959d12
fix: lint
nicolasalexandre9 Jan 28, 2025
d4f746b
fix: tests on transforms pattern
nicolasalexandre9 Jan 28, 2025
b6fc69c
chore: update ci config
nicolasalexandre9 Jan 28, 2025
3e50e66
fix: tests on condition tree parser
nicolasalexandre9 Jan 28, 2025
6b7c186
fix: condition tree transform pattern
nicolasalexandre9 Jan 28, 2025
7c2b70c
chore: update rails version in gemfile-test
nicolasalexandre9 Jan 28, 2025
591e4dd
chore: update rails version
nicolasalexandre9 Jan 28, 2025
bab1304
fix: tests
matthv Jan 29, 2025
a36413a
chore: dummy controller
matthv Jan 29, 2025
87a14da
chore: ci add services mongodb
matthv Jan 29, 2025
8c6c186
fix: ci
matthv Jan 29, 2025
010b559
fix: format_attributes for jsonapi
matthv Jan 30, 2025
c2276e3
test: add test on query builder
nicolasalexandre9 Jan 30, 2025
1da2c73
test: add test on mongoid serializer
nicolasalexandre9 Jan 30, 2025
34d9ad3
test: add test on query aggregate
nicolasalexandre9 Jan 31, 2025
c693d8d
feat(flatten): add new utils
matthv Jan 31, 2025
1961ae9
feat(flatten): option parser - auto flatten mode
matthv Feb 3, 2025
a66a995
feat(flatten): handle list_path_matching
matthv Feb 3, 2025
f31ccb1
chore: add datasource
matthv Feb 3, 2025
172e869
feat(collection): add fields with flatten mode auto
nicolasalexandre9 Feb 4, 2025
88f2ea3
feat: list_fields on schema
matthv Feb 5, 2025
2f390f6
feat(mongo): add pipeline constructor
nicolasalexandre9 Feb 5, 2025
1a13f0d
feat: add implicit relations
matthv Feb 5, 2025
826ea9b
refactor: relation generator
matthv Feb 5, 2025
e569384
fix(pipeline): compute sort
nicolasalexandre9 Feb 5, 2025
c8c6517
chore: prepare flatten mode manual
matthv Feb 5, 2025
c867969
feat: handle filter format_and_cast_leaf_value
matthv Feb 6, 2025
5ca5d05
feat: add add_null_values utils
matthv Feb 7, 2025
3efb1f2
feat: finalize aggregate route and add group-generator utils
matthv Feb 7, 2025
86c2ca3
feat(mongoid): handle create
matthv Feb 11, 2025
b1e275c
feat(mongoid): handle simple update / delete
matthv Feb 11, 2025
02e811a
feat(mongoid): handle simple update / delete
matthv Feb 11, 2025
db0b448
fix: update on embed relations
matthv Feb 12, 2025
247d296
fix(utils): add_null_values
matthv Feb 14, 2025
725fea6
fix: add_null_values
matthv Feb 17, 2025
fadbd4e
fix: tests
matthv Feb 17, 2025
3584810
fix: test
matthv Feb 17, 2025
c64eee8
fix(filter): list_relations and add tests
matthv Feb 17, 2025
77ff585
chore: remove legacy mode
matthv Feb 18, 2025
adb469c
fix: build pipeline with relations
nicolasalexandre9 Feb 18, 2025
9ac356a
fix(schema): field type array
matthv Feb 18, 2025
9bdd527
fix: reparent unflatten & reparent methods
matthv Feb 18, 2025
aa950e7
chore: add tests
matthv Feb 18, 2025
1215bc0
feat(mongo): add virtual field generatoe
nicolasalexandre9 Feb 19, 2025
1494214
chore: add tests
matthv Feb 19, 2025
e3cd883
feat(mongo): add missing methods to helpers utils
matthv Feb 20, 2025
8b4514f
fix: mongoid schema flatten mode
matthv Feb 20, 2025
ab6cd86
chore: add test on helpers
matthv Feb 21, 2025
a23cc84
fix: test add_null_values
matthv Feb 24, 2025
5723380
refactor: tests tree
matthv Feb 24, 2025
f31349a
fix: virtual field & add test
matthv Feb 25, 2025
3c733f0
chore: add first tests on lookupGenerator
matthv Feb 25, 2025
d1eb198
chore: add first test on lookupgenerator
matthv Feb 25, 2025
896b70d
chore: add test on condition
matthv Feb 25, 2025
a8647bf
fix: field generator
nicolasalexandre9 Feb 26, 2025
6f6c9d9
fix: test on collection & datasource
matthv Feb 26, 2025
f7b8052
chore: set config for dummy rails >8.1
matthv Feb 26, 2025
0a97f47
fix: field handle hash
matthv Feb 27, 2025
29ccae4
test: add tests on lookup generator
nicolasalexandre9 Feb 27, 2025
5c3ff5e
chore: add test on FieldGenerator
matthv Feb 27, 2025
41ef49c
fix: some tests
nicolasalexandre9 Feb 27, 2025
c8cec7d
refactor: remove unused code
nicolasalexandre9 Feb 27, 2025
6d82eb7
fix: some tests
nicolasalexandre9 Feb 27, 2025
13ff085
chore: fix gemfile-test
nicolasalexandre9 Feb 28, 2025
db7414a
feat(field): handle validation
matthv Feb 28, 2025
e4f96db
chore: add test on field
matthv Feb 28, 2025
ea8c8ac
fix: validation test
matthv Feb 28, 2025
1a39cba
test: add tests on mongoid datasource
nicolasalexandre9 Mar 3, 2025
bfdd929
fix: get_column_type
nicolasalexandre9 Mar 4, 2025
737497e
fix: routes declarations
nicolasalexandre9 Mar 4, 2025
3a29b29
refactor: remove unused code
nicolasalexandre9 Mar 4, 2025
20d0c39
fix: rollback delete methode format_model_name
nicolasalexandre9 Mar 6, 2025
d04b15b
fix: test
nicolasalexandre9 Mar 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- forest_admin_datasource_toolkit
- forest_admin_test_toolkit
- forest_admin_rails
- forest_admin_datasource_mongoid

steps:
- name: Checkout
Expand Down Expand Up @@ -54,6 +55,12 @@ jobs:
- forest_admin_datasource_active_record
- forest_admin_datasource_customizer
- forest_admin_datasource_toolkit
- forest_admin_datasource_mongoid
services:
mongodb:
image: mongo:latest
ports:
- 27017:27017
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -68,6 +75,16 @@ jobs:
gem install bundler
bundle install

- name: Wait for MongoDB
if: ${{ matrix.packages == 'forest_admin_datasource_mongoid' }}
run: |
for i in {1..30}; do
nc -z localhost 27017 && echo "MongoDB is up" && exit 0
echo "Waiting for MongoDB..."
sleep 1
done
exit 1

- name: Test
run: |
cd packages/${{ matrix.packages }} && \
Expand Down Expand Up @@ -109,6 +126,7 @@ jobs:
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_active_record/coverage.json:simplecov
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_customizer/coverage.json:simplecov
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_toolkit/coverage.json:simplecov
${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_mongoid/coverage.json:simplecov
debug: true

deploy:
Expand Down
33 changes: 32 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AllCops:
NewCops: enable
Exclude:
- 'packages/forest_admin_datasource_active_record/spec/dummy/**/*'
- 'packages/forest_admin_datasource_mongoid/spec/dummy/**/*'
- 'packages/forest_admin_agent/lib/forest_admin_agent/serializer/forest_serializer.rb'
- 'packages/forest_admin_agent/lib/forest_admin_agent/serializer/forest_serializer_override.rb'
- 'node_modules/semantic-release-rubygem/**/*'
Expand All @@ -16,6 +17,7 @@ Gemspec/OrderedDependencies:
- 'packages/forest_admin_agent/forest_admin_agent.gemspec'
- 'packages/forest_admin_rails/forest_admin_rails.gemspec'
- 'packages/forest_admin_datasource_toolkit/forest_admin_datasource_toolkit.gemspec'
- 'packages/forest_admin_datasource_mongoid/forest_admin_datasource_mongoid.gemspec'
- 'packages/forest_admin_test_toolkit/forest_admin_test_toolkit.gemspec'
- 'packages/forest_admin_datasource_customizer/forest_admin_datasource_customizer.gemspec'
- 'packages/forest_admin_datasource_active_record/forest_admin_datasource_active_record.gemspec'
Expand All @@ -26,6 +28,7 @@ Gemspec/RequireMFA:
- 'packages/forest_admin_agent/forest_admin_agent.gemspec'
- 'packages/forest_admin_rails/forest_admin_rails.gemspec'
- 'packages/forest_admin_datasource_toolkit/forest_admin_datasource_toolkit.gemspec'
- 'packages/forest_admin_datasource_mongoid/forest_admin_datasource_mongoid.gemspec'
- 'packages/forest_admin_test_toolkit/forest_admin_test_toolkit.gemspec'
- 'packages/forest_admin_datasource_customizer/forest_admin_datasource_customizer.gemspec'
- 'packages/forest_admin_datasource_active_record/forest_admin_datasource_active_record.gemspec'
Expand All @@ -37,6 +40,7 @@ Lint/PercentStringArray:
- 'packages/forest_admin_agent/forest_admin_agent.gemspec'
- 'packages/forest_admin_rails/forest_admin_rails.gemspec'
- 'packages/forest_admin_datasource_toolkit/forest_admin_datasource_toolkit.gemspec'
- 'packages/forest_admin_datasource_mongoid/forest_admin_datasource_mongoid.gemspec'
- 'packages/forest_admin_datasource_customizer/forest_admin_datasource_customizer.gemspec'
- 'packages/forest_admin_datasource_active_record/forest_admin_datasource_active_record.gemspec'

Expand All @@ -60,6 +64,7 @@ Style/BlockComments:
- 'packages/forest_admin_agent/spec/spec_helper.rb'
- 'packages/forest_admin_rails/spec/spec_helper.rb'
- 'packages/forest_admin_datasource_toolkit/spec/spec_helper.rb'
- 'packages/forest_admin_datasource_mongoid/spec/spec_helper.rb'
- 'packages/forest_admin_datasource_customizer/spec/spec_helper.rb'
- 'packages/forest_admin_datasource_active_record/spec/spec_helper.rb'

Expand All @@ -86,6 +91,7 @@ Style/MutableConstant:
- 'packages/forest_admin_agent/lib/forest_admin_agent/utils/schema/schema_emitter.rb'
- 'packages/forest_admin_rails/lib/forest_admin_rails/version.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/version.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/version.rb'
- 'packages/forest_admin_test_toolkit/lib/forest_admin_test_toolkit/version.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/version.rb'
- 'packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/version.rb'
Expand Down Expand Up @@ -127,7 +133,14 @@ Style/StringLiterals:
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/version.rb'
- 'packages/forest_admin_datasource_toolkit/spec/spec_helper.rb'
- 'packages/forest_admin_datasource_toolkit/forest_admin_test_toolkit.gemspec'
- 'packages/forest_admin_datasource_mongoid/forest_admin_datasource_mongoid.gemspec'
- 'packages/forest_admin_datasource_mongoid/Gemfile'
- 'packages/forest_admin_datasource_mongoid/Rakefile'
- 'packages/forest_admin_datasource_mongoid/bin/console'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/version.rb'
- 'packages/forest_admin_datasource_mongoid/spec/spec_helper.rb'
- 'packages/forest_admin_test_toolkit/forest_admin_test_toolkit.gemspec'
- 'packages/forest_admin_test_toolkit/Gemfile'
- 'packages/forest_admin_test_toolkit/Rakefile'
- 'packages/forest_admin_test_toolkit/bin/console'
Expand Down Expand Up @@ -194,6 +207,7 @@ Metrics/ParameterLists:
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/action/action_collection_decorator.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/action/dynamic_field.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/hook/context/after/hook_after_aggregate_context.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/datasource.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/schema/relations/many_to_many_schema.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/schema/column_schema.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/components/caller.rb'
Expand All @@ -208,8 +222,10 @@ Metrics/ModuleLength:
- 'packages/forest_admin_agent/spec/**/*'
- 'packages/forest_admin_datasource_active_record/spec/**/*'
- 'packages/forest_admin_datasource_toolkit/spec/**/*'
- 'packages/forest_admin_datasource_mongoid/spec/**/*'
- 'packages/forest_admin_datasource_customizer/spec/**/*'
- 'packages/forest_admin_rails/spec/**/*'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/helpers.rb'

Metrics/MethodLength:
CountAsOne: ['array', 'hash', 'method_call']
Expand Down Expand Up @@ -239,12 +255,20 @@ Metrics/MethodLength:
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/rename_field/rename_field_collection_decorator.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/action/action_collection_decorator.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/action/form_factory.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/collection.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/query.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/schema/fields_generator.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/schema/mongoid_schema.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/pipeline/filter_generator.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/pipeline/lookup_generator.rb'


Metrics/BlockLength:
Exclude:
- 'packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/collection.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/components/query/filter_factory.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/action/base_action.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/collection.rb'

Metrics/ClassLength:
Exclude:
Expand Down Expand Up @@ -273,6 +297,10 @@ Metrics/ClassLength:
- 'packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/collection.rb'
- 'packages/forest_admin_agent/lib/forest_admin_agent/utils/schema/generator_action.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/action/action_collection_decorator.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/collection.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/query.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/schema/mongoid_schema.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/pipeline/filter_generator.rb'

Style/OpenStructUse:
Exclude:
Expand All @@ -292,6 +320,7 @@ Layout/LineLength:
- 'packages/forest_admin_agent/spec/**/*'
- 'packages/forest_admin_datasource_active_record/spec/**/*'
- 'packages/forest_admin_datasource_toolkit/spec/**/*'
- 'packages/forest_admin_datasource_mongoid/spec/**/*'
- 'packages/forest_admin_datasource_customizer/spec/**/*'
- 'packages/forest_admin_rails/spec/**/*'
- 'packages/forest_admin_agent/lib/forest_admin_agent/http/forest_admin_api_requester.rb'
Expand All @@ -305,6 +334,8 @@ Layout/LineLength:
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/publication/publication_datasource_decorator.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/relation/relation_collection_decorator.rb'
- 'packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/sort/sort_collection_decorator.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/datasource.rb'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/schema/mongoid_schema.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/components/query/condition_tree/condition_tree_factory.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/utils/collection.rb'
- 'packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/components/query/filter_factory.rb'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def build(args = {})
end

def format_attributes(args)
record = args[:params][:data][:attributes]
record = args[:params][:data][:attributes] || {}

args[:params][:data][:relationships]&.map do |field, value|
schema = @collection.schema[:fields][field]

record[schema.foreign_key] = value['data'][schema.foreign_key_target] if schema.type == 'ManyToOne'
record[schema.foreign_key] = value['data']['id'] if schema.type == 'ManyToOne'
end

record || {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def handle_request(args = {})
ForestAdminAgent::Utils::QueryStringParser.parse_condition_tree(@child_collection, args)
]
),
page: ForestAdminAgent::Utils::QueryStringParser.parse_pagination(args)
page: ForestAdminAgent::Utils::QueryStringParser.parse_pagination(args),
sort: ForestAdminAgent::Utils::QueryStringParser.parse_sort(@child_collection, args)
)
projection = ForestAdminAgent::Utils::QueryStringParser.parse_projection_with_pks(@child_collection, args)
id = Utils::Id.unpack_id(@collection, args[:params]['id'], with_key: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def handle_request(args = {})
id = Utils::Id.unpack_id(@collection, args[:params]['id'], with_key: true)
condition_tree = ConditionTree::ConditionTreeFactory.match_records(@collection, [id])
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
condition_tree: ConditionTree::ConditionTreeFactory.intersect([condition_tree, scope]),
page: ForestAdminAgent::Utils::QueryStringParser.parse_pagination(args)
condition_tree: ConditionTree::ConditionTreeFactory.intersect([condition_tree, scope])
)

projection = ProjectionFactory.all(@collection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ def handle_request(args = {})
data = format_attributes(args)
record = @collection.create(@caller, data)
link_one_to_one_relations(args, record)

id = Utils::Id.unpack_id(@collection, record['id'], with_key: true)
id = ForestAdminDatasourceToolkit::Utils::Record.primary_keys(@collection, record)
filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new(
condition_tree: ConditionTree::ConditionTreeFactory.match_records(@collection, [id])
condition_tree: ConditionTree::ConditionTreeFactory.match_ids(@collection, [id])
)
records = @collection.list(@caller, filter, ProjectionFactory.all(@collection))

Expand All @@ -40,7 +39,7 @@ def handle_request(args = {})
def link_one_to_one_relations(args, record)
args[:params][:data][:relationships]&.map do |field, value|
schema = @collection.schema[:fields][field]
next unless ['OneToOne', 'PolymorphicOneToOne'].include?(schema.type)
next unless %w[OneToOne PolymorphicOneToOne].include?(schema.type)

id = Utils::Id.unpack_id(@collection, value['data']['id'], with_key: true)
foreign_collection = @datasource.get_collection(schema.foreign_collection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ def self.from_plain_object(collection, filters)

def self.parse_value(collection, leaf)
schema = Collection.get_field_schema(collection, leaf[:field])
operator = leaf[:operator].titleize.tr(' ', '_')

if operator == Operators::IN && leaf[:field].is_a?(String)
if leaf[:operator] == Operators::IN && leaf[:field].is_a?(String)
values = leaf[:value].split(',').map(&:strip)

return values.map { |item| !%w[false 0 no].include?(item) } if schema.column_type == 'Boolean'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module Related
search: nil,
search_extended: nil,
segment: nil,
sort: nil
sort: [{ ascending: true, field: 'id' }]
)
expect(projection).to eq(%w[id label])
end
Expand Down Expand Up @@ -130,7 +130,7 @@ module Related
search: nil,
search_extended: nil,
segment: nil,
sort: nil
sort: [{ ascending: true, field: 'id' }]
)
expect(projection).to eq(%w[id label])
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ module Utils
filters = { field: 'label', operator: Operators::IN, value: ' id1,id2 , id3' }

expect(condition_tree_parser.from_plain_object(collection_category, filters))
.to have_attributes(field: filters[:field], operator: filters[:operator], value: filters[:value])
.to have_attributes(field: filters[:field], operator: filters[:operator], value: %w[id1 id2 id3])
end

it 'works with "IN" on a boolean' do
filters = { field: 'active', operator: Operators::IN, value: 'true,0,false,yes,no' }

expect(condition_tree_parser.from_plain_object(collection_category, filters))
.to have_attributes(field: filters[:field], operator: filters[:operator], value: filters[:value])
.to have_attributes(field: filters[:field], operator: filters[:operator], value: [true, false, false, true, false])
end

it 'works with "IN" on a number' do
filters = { field: 'id', operator: Operators::IN, value: '1,2,3' }

expect(condition_tree_parser.from_plain_object(collection_category, filters))
.to have_attributes(field: filters[:field], operator: filters[:operator], value: filters[:value])
.to have_attributes(field: filters[:field], operator: filters[:operator], value: [1, 2, 3])
end
end
end
Expand Down
Loading