fix: update ash_sql for include_nil? fix and test it

This commit is contained in:
Zach Daniel 2024-07-16 22:39:51 -04:00
parent 2393c2c633
commit 7cf06f3956
4 changed files with 63 additions and 2 deletions

View file

@ -163,7 +163,7 @@ defmodule AshPostgres.MixProject do
defp deps do
[
{:ash, ash_version("~> 3.1 and >= 3.1.7")},
{:ash_sql, ash_sql_version("~> 0.2 and >= 0.2.20")},
{:ash_sql, ash_sql_version("~> 0.2 and >= 0.2.23")},
{:igniter, "~> 0.3"},
{:ecto_sql, "~> 3.11 and >= 3.11.3"},
{:ecto, "~> 3.11 and >= 3.11.2"},

View file

@ -1,6 +1,6 @@
%{
"ash": {:hex, :ash, "3.2.0", "9569a7d31ebbb218bbef652235989a9943a8cd0775cf8dfad3004b8399e8a8e6", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.2.12 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, ">= 0.8.1 and < 1.0.0-0", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.2.8 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aef9a42268462fc9756e5f7152a5fba54707d632787c726d4b3db462d6301d8c"},
"ash_sql": {:hex, :ash_sql, "0.2.22", "935243e93c32c0d28d8425428d876649708597b36f7b6035d4118f9684e7545c", [:mix], [{:ash, ">= 3.1.7 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "272938074895122cbd48fd05c04a2e1229bc7657b9d4690a41abd1adf4e3d3a9"},
"ash_sql": {:hex, :ash_sql, "0.2.23", "8e00592827bfc99d1d8410e600d053da99f931007a4e87eeb579a2222aa02549", [:mix], [{:ash, ">= 3.1.7 and < 4.0.0-0", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "e1902d694181e03202d3fa4b888e62146bb86ab1ffd9e45bde8d3992fa08e229"},
"benchee": {:hex, :benchee, "1.3.1", "c786e6a76321121a44229dde3988fc772bca73ea75170a73fd5f4ddf1af95ccf", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "76224c58ea1d0391c8309a8ecbfe27d71062878f59bd41a390266bf4ac1cc56d"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"},

View file

@ -378,6 +378,62 @@ defmodule AshSql.AggregateTest do
|> Ash.read_one!()
end
test "does not return nil values" do
post =
Post
|> Ash.Changeset.for_create(:create, %{title: "title"})
|> Ash.create!()
Comment
|> Ash.Changeset.for_create(:create, %{title: "bbb"})
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|> Ash.create!()
Comment
|> Ash.Changeset.for_create(:create, %{title: nil})
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|> Ash.create!()
Comment
|> Ash.Changeset.for_create(:create, %{title: "aaa"})
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|> Ash.create!()
assert %{comment_titles: ["aaa", "bbb"]} =
Post
|> Ash.Query.filter(id == ^post.id)
|> Ash.Query.load(:comment_titles)
|> Ash.read_one!()
end
test "returns nil values if `include_nil?` is set to `true`" do
post =
Post
|> Ash.Changeset.for_create(:create, %{title: "title"})
|> Ash.create!()
Comment
|> Ash.Changeset.for_create(:create, %{title: "bbb"})
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|> Ash.create!()
Comment
|> Ash.Changeset.for_create(:create, %{title: nil})
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|> Ash.create!()
Comment
|> Ash.Changeset.for_create(:create, %{title: "aaa"})
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|> Ash.create!()
assert %{comment_titles_with_nils: ["aaa", "bbb", nil]} =
Post
|> Ash.Query.filter(id == ^post.id)
|> Ash.Query.load(:comment_titles_with_nils)
|> Ash.read_one!()
end
test "with related data, it returns the value" do
post =
Post

View file

@ -606,6 +606,11 @@ defmodule AshPostgres.Test.Post do
sort(title: :asc_nils_last)
end
list :comment_titles_with_nils, :comments, :title do
sort(title: :asc_nils_last)
include_nil?(true)
end
list :uniq_comment_titles, :comments, :title do
uniq?(true)
sort(title: :asc_nils_last)