mercredi 12 août 2015

Firebase ember fire adapter fails in validation rules for parent child relationships

Firebase allows you to have validation rules ensuring that particular children exist for any given node. For example:

{
  "rules" : {
    "posts" : {
      "$postsID" : {
        ".validate" : "newData.hasChildren(['title','body','authors'])",
        ...

Above, if we try to create a node at /posts/ without giving it a title, body, or authors, Firebase will reject our request.

However, the updateRecord function in the EmberFire adapter is using separate promises to save relationships and the model itself.

So, in the example above, when we save a new post, EmberFire might attempt to write to /posts//authors/ before it writes to /posts//title and /posts//body. In that case, our validation rules will fail.

There are a couple of solutions that come to mind

  1. Patch the ember fire adapter to write all the updates to a node using a single request instead of using multiple requests.

  2. Patch the adapter to use transactions and then we can use the validations.

I am wondering if there are any other solutions that does not involve patching the adapter

PS - This is posted on github issues for Firebase as well - http://ift.tt/1f87fB6




Aucun commentaire:

Enregistrer un commentaire