rapidfsub

rapidfsub

This is Product.relationships code.
https://github.com/rapidfsub/sonet/blob/develop/test/support/lib/sonet_lib/seven_eleven/product.ex#L44

This is load test code for above relationships.
https://github.com/rapidfsub/sonet/blob/develop/test/sonet_lib/seven_eleven/product_test.exs#L24

I think three stores, stores_alt1, stores_alt2 relationships should be equivalent.
But, only the stores relationship works,
and other two relationships raise Ecto.Query.CompileError.

I’m confused how to write relationship with no_attributes? true.
Is there any proper way to write this kind of relationships correctly? @zachdaniel

Showing Posts 10 to 1

rapidfsub

rapidfsub OP

The bug I reported is fixed, but I found another one related to original one.
I opened a new issue in ash_postgres.
https://github.com/ash-project/ash_postgres/issues/413

rapidfsub

rapidfsub OP

Thanks.

zachdaniel

zachdaniel

Creator of Ash

This is fixed in main of ash_postgres. I will release new versions of ash and ash_postgres this week.

zachdaniel

zachdaniel

Creator of Ash

Thank you, I’ll take a look in the next day or two.

rapidfsub

rapidfsub OP

zachdaniel

zachdaniel

Creator of Ash

If you can, please provide a reproduction and as much detail as you can. Ideally a test I can run that reproduces the specific error :smiley:

zachdaniel

zachdaniel

Creator of Ash

** (Ecto.Query.CompileError) only one distinct expression is allowed in query
is a bug.

Please open a bug report.

rapidfsub

rapidfsub OP

I will explain more about my question.

There are three resources: Store, Inventory, Product.
Store and Product is simple resource, and Inventory is join table resource.

  • Store
    has_many :inventories
  • Product
    has_many :inventories
  • Inventory
    belongs_to :store
    belongs_to :product

I know there is many_to_many feature,
but I wanted to show you there are some hard things when using no_attributes? true.

A private project in our company uses no_attributes? true a lot
(There are some scenarios our company have, only no_attributes? true can be a solution.),
and I meet this kind of error a lot.
How can I avoid these errors and write correct relationship?
Or is this an bug?

rapidfsub

rapidfsub OP

Here are the stacktraces.

stacktrace for stores_alt1

  1) test relationships stores (SonetLib.SevenEleven.ProductTest)
     test/sonet_lib/seven_eleven/product_test.exs:24
     ** (Ecto.Query.CompileError) only one distinct expression is allowed in query
     code: Ashex.load!(product, [:stores_alt1])
     stacktrace:
       (ash_postgres 2.4.11) lib/data_layer.ex:1102: AshPostgres.DataLayer.lateral_join_query/3
       (ash_postgres 2.4.11) lib/data_layer.ex:961: AshPostgres.DataLayer.run_query_with_lateral_join/4
       (ash 3.4.35) lib/ash/actions/read/read.ex:2650: Ash.Actions.Read.run_query/4
       (ash 3.4.35) lib/ash/actions/read/read.ex:542: anonymous fn/8 in Ash.Actions.Read.do_read/5
       (ash 3.4.35) lib/ash/actions/read/read.ex:886: Ash.Actions.Read.maybe_in_transaction/3
       (ash 3.4.35) lib/ash/actions/read/read.ex:269: Ash.Actions.Read.do_run/3
       (ash 3.4.35) lib/ash/actions/read/read.ex:81: anonymous fn/3 in Ash.Actions.Read.run/3
       (ash 3.4.35) lib/ash/actions/read/read.ex:80: Ash.Actions.Read.run/3
       (ash 3.4.35) lib/ash/actions/read/relationships.ex:413: anonymous fn/2 in Ash.Actions.Read.Relationships.do_fetch_related_records/4
       (ash 3.4.35) lib/ash/actions/read/relationships.ex:65: Ash.Actions.Read.Relationships.fetch_related_records/4
       (ash 3.4.35) lib/ash/actions/read/relationships.ex:24: Ash.Actions.Read.Relationships.load/4
       (ash 3.4.35) lib/ash/actions/read/read.ex:298: Ash.Actions.Read.do_run/3
       (ash 3.4.35) lib/ash/actions/read/read.ex:81: anonymous fn/3 in Ash.Actions.Read.run/3
       (ash 3.4.35) lib/ash.ex:1859: Ash.load/3
       (ash 3.4.35) lib/ash.ex:1813: Ash.load/3
       (ash 3.4.35) lib/ash.ex:1754: Ash.load!/3
       test/sonet_lib/seven_eleven/product_test.exs:28: (test)

stacktrace for stores_alt2

  1) test relationships stores (SonetLib.SevenEleven.ProductTest)
     test/sonet_lib/seven_eleven/product_test.exs:24
     ** (Ecto.Query.CompileError) only one distinct expression is allowed in query
     code: Ashex.load!(product, [:stores_alt2])
     stacktrace:
       (ash_postgres 2.4.11) lib/data_layer.ex:1102: AshPostgres.DataLayer.lateral_join_query/3
       (ash_postgres 2.4.11) lib/data_layer.ex:961: AshPostgres.DataLayer.run_query_with_lateral_join/4
       (ash 3.4.35) lib/ash/actions/read/read.ex:2650: Ash.Actions.Read.run_query/4
       (ash 3.4.35) lib/ash/actions/read/read.ex:542: anonymous fn/8 in Ash.Actions.Read.do_read/5
       (ash 3.4.35) lib/ash/actions/read/read.ex:886: Ash.Actions.Read.maybe_in_transaction/3
       (ash 3.4.35) lib/ash/actions/read/read.ex:269: Ash.Actions.Read.do_run/3
       (ash 3.4.35) lib/ash/actions/read/read.ex:81: anonymous fn/3 in Ash.Actions.Read.run/3
       (ash 3.4.35) lib/ash/actions/read/read.ex:80: Ash.Actions.Read.run/3
       (ash 3.4.35) lib/ash/actions/read/relationships.ex:413: anonymous fn/2 in Ash.Actions.Read.Relationships.do_fetch_related_records/4
       (ash 3.4.35) lib/ash/actions/read/relationships.ex:65: Ash.Actions.Read.Relationships.fetch_related_records/4
       (ash 3.4.35) lib/ash/actions/read/relationships.ex:24: Ash.Actions.Read.Relationships.load/4
       (ash 3.4.35) lib/ash/actions/read/read.ex:298: Ash.Actions.Read.do_run/3
       (ash 3.4.35) lib/ash/actions/read/read.ex:81: anonymous fn/3 in Ash.Actions.Read.run/3
       (ash 3.4.35) lib/ash.ex:1859: Ash.load/3
       (ash 3.4.35) lib/ash.ex:1813: Ash.load/3
       (ash 3.4.35) lib/ash.ex:1754: Ash.load!/3
       test/sonet_lib/seven_eleven/product_test.exs:32: (test)
zachdaniel

zachdaniel

Creator of Ash

What are the details of the error? Just knowing Ecto.Query.CompileError is not really useful without more information.

With that said, could you also describe specifically what the stores relationship is meant to provide?

I can’t really give advice as I don’t know what you’re specifically looking to do.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews