Skip to content

Resolves #263 added a means to disable attaching relationship metadata on unresolved includes#264

Open
ibustosatlegalzoom wants to merge 3 commits intodevour-js:masterfrom
ibustosatlegalzoom:issue_263
Open

Resolves #263 added a means to disable attaching relationship metadata on unresolved includes#264
ibustosatlegalzoom wants to merge 3 commits intodevour-js:masterfrom
ibustosatlegalzoom:issue_263

Conversation

@ibustosatlegalzoom
Copy link
Copy Markdown
Contributor

Screenshot

N/A

What Changed & Why

Learn more at #263

Introduced a flag attachRelationshipDataOnUnresolvedIncludes which by default is set to true for backwards-compatibility purposes.

When set to true, Devour will continue to attach relationship metadata in the client's response on unresolved includes as it normally does.

When set to false however, Devour will abstain from attaching such metatada. This applies both for relationships of type hasMany and hasOne-

Testing

Just run the tests.

Documentation

Updated the README file with instructions.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new configuration flag attachRelationshipDataOnUnresolvedIncludes to control whether relationship metadata (id, type) should be attached to responses when the related resources are not included in the API response. The flag defaults to true for backward compatibility, but when set to false, only fully resolved (included) relationships will have their data populated.

Key changes:

  • Added attachRelationshipDataOnUnresolvedIncludes flag to the JsonApi constructor with a default value of true
  • Modified deserialize logic to conditionally attach relationship data based on the flag for both hasOne and hasMany relationships
  • Added comprehensive test coverage for both relationship types with the new flag disabled
  • Updated README with documentation explaining the new feature

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/index.js Adds the new attachRelationshipDataOnUnresolvedIncludes configuration option to the defaults and assigns it to the instance
src/middleware/json-api/_deserialize.js Wraps the unresolved relationship data attachment logic in conditional checks for both attachHasOneFor and attachHasManyFor functions
test/api/deserialize-test.js Adds two new test cases verifying the flag prevents relationship metadata attachment for unresolved hasMany and hasOne relationships
README.md Documents the new flag and its purpose in the Relationships section

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/api/deserialize-test.js Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
auvipy and others added 2 commits December 2, 2025 20:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants