0
votes

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 - https://github.com/firebase/emberfire/issues/304

1

1 Answers

0
votes

Unfortunately you are correct. At the moment, hasMany relationship links are saved in a series of separate requests to the server. This will cause issue with security rules that require there to be at least one hasMany link.

Lets keep discussing this in the GitHub issue. It is possible we will change the behavior of the adapter.