Closed isfando closed 3 years ago
@AaronLasseigne , any guidance on this if possible
Yup, it's a circular dependency. I can't really offer help here. You'll have to rethink how you're approaching the problem. Best of luck.
class XYZ < ActiveInteraction::Base
object :foo, class: X, default: -> { baz&.contact }
object :bar, class: X, default: -> { X.unscoped.find(baz.duplicate_contact_id) }
object :baz, default: -> {
ContactDuplicateContact.where(contact_id: foo.id, duplicate_contact_id: bar.id).first!
}
def execute
...
end
end
When i call the interaction as following where "bar_obj" is not nil XYZ.run!(baz: baz_obj)
But why is it undefined in default lambda of "bar", which fails with following error because it finds baz as undefined
NoMethodError:
undefined method `duplicate_contact_id' for nil:NilClass
We do checking of defaults early in process so it's running it and assigning it before the other objects have become available.
When i call the interaction as following where "bar_obj" is not nil XYZ.run!(baz: baz_obj)
the default initialization of "bar" fails with following error because it finds baz as undefined
I can circumvent the error by changing initialization order i.e. initializing baz as the first variable which makes the above scenario successful
BUT it then fails when the interaction is called with XYZ.run!(foo: foo_obj, bar:bar _obj)
the default initialization of "baz" fails with following error because it finds "foo" and "bar" as undefined
It look analogous to a circular dependency problem with defaults. One dirty solution where we expose extra complication and declare everything directly would be obviously this
BUT Can anybody suggest a better way to solve this?