mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
fix: fix required relationships and add test
This commit is contained in:
parent
e65d47d386
commit
11d658d077
2 changed files with 14 additions and 2 deletions
|
@ -797,13 +797,13 @@ defmodule Ash.Changeset do
|
|||
# Attributes that are private and/or are the source field of a belongs_to relationship
|
||||
# are typically not set by input, so they aren't required until the actual action
|
||||
# is run.
|
||||
defp attributes_to_require(resource, _private_and_belongs_to? = true) do
|
||||
defp attributes_to_require(resource, true = _private_and_belongs_to?) do
|
||||
resource
|
||||
|> Ash.Resource.Info.attributes()
|
||||
|> Enum.reject(&(&1.allow_nil? || &1.generated?))
|
||||
end
|
||||
|
||||
defp attributes_to_require(resource, _private_and_belongs_to? = false) do
|
||||
defp attributes_to_require(resource, false = _private_and_belongs_to?) do
|
||||
belongs_to =
|
||||
resource
|
||||
|> Ash.Resource.Info.relationships()
|
||||
|
|
|
@ -581,6 +581,18 @@ defmodule Ash.Test.Actions.CreateTest do
|
|||
|> Api.create!()
|
||||
end
|
||||
end
|
||||
|
||||
test "allows creating with the required belongs_to relationship" do
|
||||
author =
|
||||
Author
|
||||
|> Ash.Changeset.for_create(:create, bio: "best dude")
|
||||
|> Api.create!()
|
||||
|
||||
ProfileWithBelongsTo
|
||||
|> Ash.Changeset.for_create(:create)
|
||||
|> Ash.Changeset.replace_relationship(:author, author)
|
||||
|> Api.create!()
|
||||
end
|
||||
end
|
||||
|
||||
describe "list type" do
|
||||
|
|
Loading…
Reference in a new issue