Fix PORO resource creation without find_by_key override #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When creating a PORO (Plain Old Ruby Object) resource that:
.allmethodfind_by_keyfind_fragmentsThe
createoperation would fail withNoMethodError: undefined method 'all'.Root Cause
The current implementation of
Processor#create_resourcecallsfind_resource_setafter creating a resource, which internally calls:find_fragmentsfind_fragments_for_non_active_record(for PORO)find_by_key(default implementation)records_base_model_class.all❌ NoMethodErrorSolution
This PR restores the v0.9.x behavior for PORO models: when
_model_classdoesn't respond to:all, the created resource is passed directly toResourceSetwithout attempting to re-fetch it.ActiveRecord resources continue to use the optimized
find_resource_setpath with efficient queries and includes.Changes
lib/jsonapi/processor.rb- Added PORO detection increate_resourcemethodfind_by_keyoverrideTesting
✅ All existing tests pass:
✅ New test added:
test_create_poro_without_find_by_key_overrideBackward Compatibility
This change maintains full backward compatibility:
find_by_keyoverride: No behavior change🤖 Generated with Claude Code