Skip to content

Conversation

@zackattackz
Copy link
Contributor

Adds a transformer on relationships.{has_one, has_many} DSLs to automatically set no_attributes? to true if manual is set.

Reworks logic in places that use no_attributes? and manual together to take this new implication into consideration. (read.ex, relationships.ex, and schema.ex)

Adds some tests to ensure that this implication holds. Also adds regression tests to ensure that select callback for manual relationships is respected.

Notes

  1. Should we allow overriding no_attributes?: false in manual relationships? (That is, change the transformer logic to NOT set no_attributes?: true if they've manually specified it as false in the DSL)
  2. Do you think any other ash project repos may need similar logic changes like the ones made here? (e.g like in read.ex)

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • 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

Adds a transformer on relationships.{has_one, has_many} DSLs to automatically set `no_attributes?` to `true` if `manual` is set.

Reworks logic in places that use `no_attributes?` and `manual` together to take this new implication into consideration. (read.ex, relationships.ex, and schema.ex)

Adds some tests to ensure that this implication holds. Also adds regression tests to ensure that `select` callback for manual relationships is respected.
#
# SPDX-License-Identifier: MIT

defmodule Ash.Resource.Relationships.SharedTransformers do
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a different shared module that we use for shared helpers across relationships, lets put it there instead of adding a new module: Ash.Resource.Relationships.SharedOptions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in latest commit.

Also opened ash-project/ash_sql#213 to fix the issue with this PR + ash_postgres.

@zackattackz
Copy link
Contributor Author

ash_postgres may need some changes too, looking into it

@zackattackz
Copy link
Contributor Author

Yeah it seems like ash_postgres has some failures in certain tests with ash set to this branch. Will take a look tmmrw!

zackattackz added a commit to zackattackz/ash_sql that referenced this pull request Feb 10, 2026
…ggregates

1. Refactor a large conditional branch in `AshSql.Aggregate.get_subquery` to use a new multi-head private function instead of nested ifs.
2. Make it so that the case where the relationship is manual matches BEFORE the case where the relationship is no_attributes?: true

This is necessary in order to pass ash_postgres tests when running against ash with this PR applied: ash-project/ash#2562
@zackattackz
Copy link
Contributor Author

Basically, like the issue in ash_sql, any ash extensions / data layers or whatever that have code that tests something like:

if relationship.no_attributes?:
    ...something
else if relationship.manual:
    ...do something else

Has the potential to break since now after this PR the no_attributes? branch will execute instead of the manual one

@zackattackz
Copy link
Contributor Author

zackattackz commented Feb 10, 2026

^ So they can pretty much be fixed by just doing the manual case first. (like I did in the ash_sql PR)

if relationship.manual:
    ...do something else
else if relationship.no_attributes?:
    ...something

zachdaniel pushed a commit to ash-project/ash_sql that referenced this pull request Feb 11, 2026
…ggregates (#213)

1. Refactor a large conditional branch in `AshSql.Aggregate.get_subquery` to use a new multi-head private function instead of nested ifs.
2. Make it so that the case where the relationship is manual matches BEFORE the case where the relationship is no_attributes?: true

This is necessary in order to pass ash_postgres tests when running against ash with this PR applied: ash-project/ash#2562
@zachdaniel zachdaniel merged commit 27c9fa4 into ash-project:main Feb 11, 2026
45 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

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.

2 participants