fix: allow auto builds to be replaced by explicit relate commands.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d5be51556d
commit
f8480ec8e7
2 changed files with 14 additions and 2 deletions
|
@ -146,11 +146,11 @@ defmodule Smokestack.RelatedBuilder do
|
||||||
|> Keyword.get(:build, [])
|
|> Keyword.get(:build, [])
|
||||||
|> List.wrap()
|
|> List.wrap()
|
||||||
|> Enum.concat(factory.auto_build)
|
|> Enum.concat(factory.auto_build)
|
||||||
|> List.wrap()
|
|
||||||
|> Enum.map(fn
|
|> Enum.map(fn
|
||||||
{key, value} -> {key, value}
|
{key, value} -> {key, value}
|
||||||
key when is_atom(key) -> {key, []}
|
key when is_atom(key) -> {key, []}
|
||||||
end)
|
end)
|
||||||
|
|> remove_explicit_relates(options)
|
||||||
|> Enum.reduce_while({:ok, attrs}, fn {relationship, nested_builds}, {:ok, attrs} ->
|
|> Enum.reduce_while({:ok, attrs}, fn {relationship, nested_builds}, {:ok, attrs} ->
|
||||||
case build_related(
|
case build_related(
|
||||||
attrs,
|
attrs,
|
||||||
|
@ -164,6 +164,18 @@ defmodule Smokestack.RelatedBuilder do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp remove_explicit_relates(builds, options) do
|
||||||
|
relates =
|
||||||
|
options[:relate]
|
||||||
|
|> List.wrap()
|
||||||
|
|> Map.new()
|
||||||
|
|
||||||
|
builds
|
||||||
|
|> Enum.reject(fn {key, _value} ->
|
||||||
|
is_map_key(relates, key)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
defp build_related(attrs, relationship, factory, options) do
|
defp build_related(attrs, relationship, factory, options) do
|
||||||
ash_relationship = Resource.Info.relationship(factory.resource, relationship)
|
ash_relationship = Resource.Info.relationship(factory.resource, relationship)
|
||||||
build_related(attrs, relationship, factory, options, ash_relationship)
|
build_related(attrs, relationship, factory, options, ash_relationship)
|
||||||
|
|
|
@ -198,7 +198,7 @@ defmodule Smokestack.DslTest do
|
||||||
post = AutoBuildRelateFactory.insert!(Post, relate: [author: author])
|
post = AutoBuildRelateFactory.insert!(Post, relate: [author: author])
|
||||||
|
|
||||||
# The auto-build should not be used - the existing author should be used
|
# 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
|
assert post.author.id == author.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue