Skip to content

Fix relationship issue 28#419

Open
lincolnhuls wants to merge 1 commit intoash-project:mainfrom
lincolnhuls:fix-json-issue28
Open

Fix relationship issue 28#419
lincolnhuls wants to merge 1 commit intoash-project:mainfrom
lincolnhuls:fix-json-issue28

Conversation

@lincolnhuls
Copy link

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • [x ] I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

I’ve added support for join-table fields via JSON:API meta on relationship resource identifiers. Resources can now declare relationship_meta in their json_api config, which maps per-relationship meta keys to join attributes. In AshJsonApi.Controllers.Helpers, many-to-many relationship routes use that mapping to turn incoming identifiers with meta into the single map of fields that manage_relationship expects (including both the related ID and the derived join attributes), and we retain the meta per identifier so the response can echo it back. In AshJsonApi.Serializer, relationship responses now attach that meta onto each identifier, and there’s a ManyToMany-specific add_relationship_meta/4 clause wired to the same mapping when join rows are loaded. I extended the existing relationship acceptance test to assert that posting identifiers with meta results in the same meta being present on the identifiers in the response, while behavior for relationships without relationship_meta or without meta remains unchanged.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9bdddb6e6d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +24 to +27
case Map.fetch(identifier_meta, AshJsonApi.Resource.encode_primary_key(record)) do
{:ok, meta_for_identifier} when is_map(meta_for_identifier) and
map_size(meta_for_identifier) > 0 ->
Map.put(payload, :meta, meta_for_identifier)

Choose a reason for hiding this comment

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

P2 Badge Gate identifier meta echo behind relationship_meta mapping

serialize_to_many_relationship/5 now unconditionally overlays request.assigns.relationship_identifier_meta onto each relationship identifier, but that assign is populated from raw request meta in add_to_relationship/2 without checking whether the relationship has a relationship_meta mapping (or whether keys are mapped). As a result, POST /relationships can return arbitrary meta keys that were never persisted (e.g., on unmapped relationships or unmapped keys), so the write response can disagree with stored data and later reads.

Useful? React with 👍 / 👎.

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.

1 participant