fix: allow auto builds to be replaced by explicit relate commands.
This commit is contained in:
parent
730073e179
commit
a681d6e155
2 changed files with 11 additions and 2 deletions
|
@ -146,11 +146,11 @@ defmodule Smokestack.RelatedBuilder do
|
|||
|> Keyword.get(:build, [])
|
||||
|> List.wrap()
|
||||
|> Enum.concat(factory.auto_build)
|
||||
|> List.wrap()
|
||||
|> Enum.map(fn
|
||||
{key, value} -> {key, value}
|
||||
key when is_atom(key) -> {key, []}
|
||||
end)
|
||||
|> remove_explicit_relates(options)
|
||||
|> Enum.reduce_while({:ok, attrs}, fn {relationship, nested_builds}, {:ok, attrs} ->
|
||||
case build_related(
|
||||
attrs,
|
||||
|
@ -164,6 +164,15 @@ defmodule Smokestack.RelatedBuilder do
|
|||
end)
|
||||
end
|
||||
|
||||
defp remove_explicit_relates(builds, options) do
|
||||
relates = Map.new(options[:relate])
|
||||
|
||||
builds
|
||||
|> Enum.reject(fn {key, _value} ->
|
||||
is_map_key(relates, key)
|
||||
end)
|
||||
end
|
||||
|
||||
defp build_related(attrs, relationship, factory, options) do
|
||||
ash_relationship = Resource.Info.relationship(factory.resource, relationship)
|
||||
build_related(attrs, relationship, factory, options, ash_relationship)
|
||||
|
|
|
@ -198,7 +198,7 @@ defmodule Smokestack.DslTest do
|
|||
post = AutoBuildRelateFactory.insert!(Post, relate: [author: author])
|
||||
|
||||
# The auto-build should not be used - the existing author should be used
|
||||
assert Ash.count(Author) == 1
|
||||
assert Ash.count!(Author, domain: Support.Domain) == 1
|
||||
assert post.author.id == author.id
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue