ash_postgres icon indicating copy to clipboard operation
ash_postgres copied to clipboard

`has_one` with `no_attributes? true` and `from_many? true` does not apply limiting to the query

Open smt116 opened this issue 1 year ago • 4 comments

Describe the bug It is the same issue like https://github.com/ash-project/ash_postgres/issues/173. Having the following relationship:

has_one :latest_exchange_rate, App.Resources.ExchangeRate do
  api App.Api
  from_many? true
  no_attributes? true
  private? true
  sort inserted_at: :desc
end

Ignores from_many?: true and assigns a list of all records. I can see that the SQL query does not include the LIMIT statement.

Expected behavior It should include LIMIT 1 in the SQL query and make the relationship refer to a single entity.

Runtime

  • Elixir version 1.15.7-otp-26
  • Erlang version 26.0.2
  • OS macOS
  • Ash version 2.21.2
  • Ash Postgres version 1.5.23

smt116 avatar Apr 17 '24 10:04 smt116

Is this when loading the relationship? In what context did you observe this behavior?

zachdaniel avatar Apr 19 '24 13:04 zachdaniel

oh, I see. its not honoring it in exists? Interesting...

zachdaniel avatar Apr 19 '24 13:04 zachdaniel

Is this when loading the relationship? In what context did you observe this behavior?

Yes. When I App.API.load!(record, :this_relation), the record.this_relation will include all the records from the database instead of just that one defined by the relation (from many + sorting).

smt116 avatar Apr 19 '24 15:04 smt116

I can't reproduce this. I think we'll need either an example test case or a reproduction project to move forward. The 2.0 github branch is up to date with the latest 2.0 version.

zachdaniel avatar Apr 20 '24 13:04 zachdaniel