Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parent tracking for array attributes #40

Open
DmitryTsepelev opened this issue Sep 19, 2019 · 3 comments
Open

Add parent tracking for array attributes #40

DmitryTsepelev opened this issue Sep 19, 2019 · 3 comments
Labels
good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed

Comments

@DmitryTsepelev
Copy link
Owner

More details to be added, reference is here

@DmitryTsepelev DmitryTsepelev added good first issue Good for newcomers help wanted Extra attention is needed labels Sep 19, 2019
@ivandenysov
Copy link

using #parent inside of array attribute worked for me. Is this issue outdated? 🤔

@DmitryTsepelev
Copy link
Owner Author

DmitryTsepelev commented May 7, 2020

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

@jessevdp
Copy link

jessevdp commented May 31, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants