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

Problems with nested arrays #6

Open
ncirkel opened this issue Sep 23, 2012 · 4 comments
Open

Problems with nested arrays #6

ncirkel opened this issue Sep 23, 2012 · 4 comments

Comments

@ncirkel
Copy link

ncirkel commented Sep 23, 2012

When calling some mutator methods on nested arrays (like collection.id.nested.array.0), the array is emptied.

After some debugging, I found the problem to be in /lib/index.js, line 326:
var arr = found && found[relPath];

The stored array is retreived, but not found: found['collection.id.nested.array'] returns null.

@acheron0
Copy link

I see the same thing, on the same line. Did anything come of this?

@IvanGaravito
Copy link

Hi, I got the same problem at my app when I started to use the racer-db-mongo plugin. Then after some debugging I figured out that this can be solved using the callback function when calling the mutator methods remove and insert and move, because the nested array is emptied and synced back to the Mongo DB, so before this happens you need to do the following:

  // Removing an item
  collection.remove(indx, function () {
    collection.set(collection.get())
  })

  // Inserting an item
  collection.insert(indx, obj, function () {
    collection.set(collection.get())
  })

  // Moving an item
  collection.move(from, to, function () {
    collection.set(collection.get())
  })

The push mutator only needs the nested array to be initialized to work alright.

  if (!collection.get()) collection.set([])
  collection.push(obj)

This not solves the problem, but keeps your app working.

@acheron0
Copy link

That did work. Thanks so much!

@bdoms
Copy link

bdoms commented Mar 20, 2013

I am currently experiencing something that seems like a related problem: I'm trying to subscribe within an array, and it doesn't work.

Doing model.subscribe('collection.id.nested.array') works fine and if I print out the array I can see all the data is there.

But doing model.subscribe('collection.id.nested.array.0') doesn't work at all. It returns an empty object, even when I know data is there.

What's funny is that this works fine with the in-memory data store, but as soon as I started using racer-db-mongo it started failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants