polymerfire icon indicating copy to clipboard operation
polymerfire copied to clipboard

Document firebase-document workaround to immutability of firebase-query

Open miztroh-zz opened this issue 9 years ago • 3 comments

@cdata Mentions using firebase-document as a means of adding a new item to an array being queried by firebase-query. As the results of the query are immutable, this is a key piece of functionality in trying to get back to what could be accomplished through the old firebase-collection. See https://github.com/firebase/polymerfire/issues/15.

miztroh-zz avatar Aug 25 '16 01:08 miztroh-zz

As a workaround, you can programatically add a document:

var doc = this.create('firebase-document', {
  data: newDoc
});

doc.save('/foo/path');

This will actually do a firebase push(...) on /foo/path, so newDoc will be added with a generated ID. Your firebase-query will pick this change up too.

Also the reason I create the element instead of have it in the template... this is because after calling save(...), the path will be set. So all future save(...) calls will try update the same item rather than push a new one.

43081j avatar Aug 30 '16 14:08 43081j

I was waiting for an answer like that for weeks!

alejohann avatar Sep 05 '16 00:09 alejohann

Starting some thinking about how we could do this "for real" in a more built-in way. #112 offers online-only methods that work directly with the Firebase SDK, but I don't think I'd like to merge it until I can rationalize it with offline behavior.

mbleigh avatar Sep 09 '16 07:09 mbleigh