Hello,
I believe I discovered a bug somewhere in Ash - I’m just unsure where exactly.
I have prepared a repo with more details (GitHub - chinponya/ash_join_bug) but I will summarize the problem here as well.
Suppose we have an action like this:
read :with_filtered_external_relationship do
prepare build(load: [:resource_on_different_datalayer])
filter expr(resource_on_different_datalayer.value == "something")
end
Where as the name of resource_on_different_datalayer would suggest, it exists on a different data layer, which in this case is mysql.
When loading this action and there is more than 1 result, the generated query will always return 0 results.
iex> AshJoinBug.Resources.Resource1PG.read_with_filtered_external_relationship! |> Enum.count
01:44:58.211 [debug] QUERY OK source="resource2mysql" db=7.9ms queue=0.2ms idle=1225.4ms
SELECT r0.`id`, r0.`resource1_id`, r0.`value` FROM `resource2mysql` AS r0 WHERE (CAST(r0.`value` AS char) = CAST(? AS char)) ["other-value-0"]
01:44:58.216 [debug] QUERY OK source="resource1pg" db=1.1ms queue=2.3ms idle=1258.9ms
SELECT r0."id", r0."resource2_id", r0."value" FROM "resource1pg" AS r0 WHERE (r0."id"::uuid = $1::uuid) AND (r0."id"::uuid = $2::uuid) ["3ce62794-4e9c-4b73-b77c-28553a30eb49", "fdbdada6-a1f2-4741-83a3-c09dd84dd4ea"]
0
Thank you for reporting this issue. Please open a bug report against the ash repository, and I will look into it this week Thank you as well for providing a reproduction, that always helps considerably. Please include a link to that in the issue.