You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Are there any reasons why you decided to rewrite filter/sort/pagination workflow?
I've played a little with monkey patching, and looks like using filters from JR is possible.
Here is my code, it's working within my application.
Note: it breaks core functionality for usage with non-AR objects, and can break something else, be careful if you want to use it.
moduleJSONAPI::UtilsmoduleResponsemoduleFormattersdefjsonapi_format(object,options={})operations=@request.operationsunlessJSONAPI.configuration.resource_cache.nil?operations.each{|op| op.options[:cache_serializer]=resource_serializer}endifobject.respond_to?(:to_ary)operations.each{ |op| op.options[:context][:records]=object}results=process_operations(operations)elseresults=JSONAPI::OperationResults.newrecord=turn_into_resource(object,options)results.add_result(JSONAPI::ResourceOperationResult.new(:ok,record))end@_response_document=create_response_document(results)@_response_document.contentsendendendendmoduleJSONAPIclassResourceclass << selfdefrecords(options={})options.dig(:context,:records) || _model_class.allenddefapply_included_resources_filters(records,options={})include_directives=options[:include_directives]returnrecordsunlessinclude_directivesrelated_directives=include_directives.include_directives.fetch(:include_related)related_directives.reduce(records)do |memo,(relationship_name,config)|
relationship=_relationship(relationship_name)nextmemounlessrelationshipfiltering_resource=relationship.resource_klass# Don't try to merge where clauses when relation isn't already being joined to query.nextmemounlessconfig[:include_in_join]filters=config[:include_filters]nextmemounlessfiltersrel_records=filtering_resource.apply_filters(filtering_resource.records({}),filters,options).references(relationship_name)memo.merge(rel_records)endendendendend
The text was updated successfully, but these errors were encountered:
Since https://github.com/cerebris/jsonapi-resources/releases/tag/v0.9.4 JR allows to filter records on nested relationship values while JU allows filtering only by
where
condition.Are there any reasons why you decided to rewrite filter/sort/pagination workflow?
I've played a little with monkey patching, and looks like using filters from JR is possible.
Here is my code, it's working within my application.
Note: it breaks core functionality for usage with non-AR objects, and can break something else, be careful if you want to use it.
The text was updated successfully, but these errors were encountered: