Support key duplication in SeedFactory.Test.produce/1
#2
Replies: 3 comments
-
I understand your expectation but I'm afraid it can't work due to more complex cases 🙂 produce [:user, company: :company1, company: :company2] then which company the user should belong to? 🙂 |
Beta Was this translation helpful? Give feedback.
-
None of them would be my initial expectation. The company would be either taken from the However you could always go with Keyword semantics and choose the first I can see not depending on the context map keys being useful to preventing a lot of „rekeying“ between entities. |
Beta Was this translation helpful? Give feedback.
-
No, it doesn't work like this 🙂 produce [:user, company: :company1] is equivalent to setup ctx do
rebind(ctx, [company: :company1], fn ctx ->
# everything that is executed here will refer to :company1 instead of :company
# if we produce :company entity, it will be produced as :company1
# if :create_user command needs :company, it will be taken from the context using :company1 key
ctx
|> exec(:create_company)
|> exec(:create_user)
end)
end |
Beta Was this translation helpful? Give feedback.
-
It seems
doesn't work, while doing the same in multiple lines works just fine.
I'd expect both to work just fine.
Beta Was this translation helpful? Give feedback.
All reactions