Open DmitryTsepelev opened 5 years ago
using #parent inside of array attribute worked for me. Is this issue outdated? 🤔
Hi @ivan-denysov! If I recall correctly, the issue was related to updates (from this comment):
... direct StoreModel's Array mutation, it won't update a parent until one of the accessor methods gets called
In other words, it might not work if you take and array and add the element to it, something like:
config = Configuration.new
product.configurations << config
config.parent # => nil
product.configurations
config.parent # => Product
Hey,
Has anything changed regarding this issue?
I just ran into a situation where I'll be needing a reference to the parent of a StoreModel in an array.
(I have a large JSON document with references between arrays. And want to create easy access to these references. For example:)
{
foos: [
{ id: '...', bar_id: '' }
],
bars: [
{ id: '...' }
]
}
configuration.foos.first.bar
If this behavior still isn't correct for nested store models in arrays I might be able to free up an afternoon and take a crack at fixing this.
Semi related: Is there any documentation on the #parent behavior of a StoreModel? I'm mostly wondering how to "set" the parent in situations like a test, so I could mock out the parent object, or at least supply a very small test double to play the parent role.
More details to be added, reference is here