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

Cannot create property '$key' on boolean 'true' #6

Closed
ExWei opened this issue May 20, 2016 · 6 comments
Closed

Cannot create property '$key' on boolean 'true' #6

ExWei opened this issue May 20, 2016 · 6 comments

Comments

@ExWei
Copy link

ExWei commented May 20, 2016

Description

When using <firebase-query> with data structure like

{
$id: true
}

it throws an error
Cannot create property '$key' on boolean 'true'

Steps to reproduce

Create data like

{
    "notes-by-user": {
        "userId1": {
            "noteId1": true,
            "noteId2": true,
        }
    }
}

and <firebase-query> element like

<firebase-query
   path="/notes-by-user/userId1"
   data="{{notes}}">
</firebase-query>
@cdata
Copy link
Contributor

cdata commented May 20, 2016

Hi, thanks for reporting. Using <firebase-query> on locations where all of the children have primitive (boolean, string, number) values is not supported. Please consider nesting these values in objects.

@darktears
Copy link

darktears commented Jun 3, 2016

But https://firebase.google.com/docs/database/web/structure-data#fanout actually give the above as an example. So how you reproduce the advice in the link so that it works with firebase-query?

@darktears
Copy link

@cdata this limitation pretty much kills doing fast lookup on the key. In the example I pasted there is no way one could do groups/[[an_id]]. Now one has to get the entire collection (groups) and iterate over it, it doesn't seem to scale TBH. Maybe you have a better suggestion.

@salah-saleh
Copy link

Hi @cdata, I also stumbled upon this issue today. I think this limitation is a real concern and the issue shouldn't be closed without fixing, or what do you think?

@midesweb
Copy link

midesweb commented Jul 28, 2016

As workaround you can use firebase-document instead of firebase-query.
And then use a new element to convert your object into an array, like this:

<firebase-document
      app-name="{{firebaseApp}}"
      path="some/path"
      data="{{dataObject}}"
></firebase-document>
<object-to-array
      object="[[dataObject]]"
      array="{{dataArray}}"
></object-to-array>

The element "object-to-array" should be like this:

<dom-module id="object-to-array">
  <script>
  (function() {
    'use strict';

    Polymer({
      is: 'object-to-array',

      properties: {
        object: {
          type: Object,
          observer: 'toArray'
        },
        array: {
          type: Array,
          value: function(){
            return [];
          },
          notify: true
        }
      },
      toArray: function(o) {
          var numelems = this.array.length;
          this.splice('array', 0, numelems);
          this.async(this.renewContent, 1);
      },
      renewContent: function() {
        for (var id in this.object){
            this.push('array', id);
          }
      }
    });
  })();
  </script>
</dom-module>

@bvhme
Copy link

bvhme commented Jul 29, 2016

We've also structured our firebase this way according with the Firebase docs' explanation that you should work in the way @ExWei showed. I found out this didn't work when I noticed that firebase-query misses a orderByValue option. Our whole platform is built on this design pattern, so upgrading from firebase-element to polymerfire is very dificult for us.

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

6 participants