0

Lets say I have a firebase and I want to add Book and Chapter objects to the root node to look like this.

example: {
  books: {
    book_id: {//book object}
  }
  chapters: {
    chapter_id: {//chapter object}
  }
}

The specific problem I am having is how do I have a blank chapters reference without objects underneath it. Like the following

example: {
  books: {
    book_id: {//book object}
  }
  chapters: {
    //this has no objects underneath it
  }
}

You cannot just leave it blank in firebase or the chapters reference will disappear. I thought maybe I could just add a .keep or something to the chapters reference, but that did not work either. Also, if I delete all of the chapter objects from underneath the chapters reference it deletes the chapters reference.

The main reason I want to have these blank references is so that I can delete all of the objects from a certain reference, but then keep the reference in firebase so I can write more objects to it. So if there is another way of accomplishing that using firebase/emberFire it would be nice to know.

Jacob Juby
  • 33
  • 3
  • 2
    Note that you don't need to "create" a path before writing to it, so even though your empty objects have been removed, you can still retrieve results for them (they'll be empty / null) or write to deeper paths (`chapters/something/somethingelse`) at any time. – Rob DiMarco Apr 29 '14 at 22:24
  • @RobDiMarco In emberFire this doesn't seem to work – Jacob Juby Apr 30 '14 at 12:02
  • possible duplicate of [How to handle empty arrays in Firebase?](http://stackoverflow.com/questions/15408416/how-to-handle-empty-arrays-in-firebase) – Kato May 01 '14 at 20:59

0 Answers0