{"action":"created","issue":{"url":"https://api.github.com/repos/firebase/emberfire/issues/246","labels_url":"https://api.github.com/repos/firebase/emberfire/issues/246/labels{/name}","comments_url":"https://api.github.com/repos/firebase/emberfire/issues/246/comments","events_url":"https://api.github.com/repos/firebase/emberfire/issues/246/events","html_url":"https://github.com/firebase/emberfire/issues/246","id":69802729,"number":246,"title":"Does EmberFire make multiple calls to the server when persisting relationships?","user":{"login":"jamesdixon","id":110114,"avatar_url":"https://avatars.githubusercontent.com/u/110114?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesdixon","html_url":"https://github.com/jamesdixon","followers_url":"https://api.github.com/users/jamesdixon/followers","following_url":"https://api.github.com/users/jamesdixon/following{/other_user}","gists_url":"https://api.github.com/users/jamesdixon/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesdixon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesdixon/subscriptions","organizations_url":"https://api.github.com/users/jamesdixon/orgs","repos_url":"https://api.github.com/users/jamesdixon/repos","events_url":"https://api.github.com/users/jamesdixon/events{/privacy}","received_events_url":"https://api.github.com/users/jamesdixon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-21T10:11:01Z","updated_at":"2015-04-22T22:47:02Z","closed_at":null,"body":"Hi,\r\n\r\nI have a simple hasMany --> belongsTo relationship between two models, `business` and `employee`, that I'm creating during a signup process. I've been toying around with the security rules for this to only allow a `business` to only be written to by an administrator of that business or only when the business currently doesn't exist (e.g. pre-signup). Here's the rule I'm using:\r\n\r\n```javascript\r\n\"businesses\": {\r\n      // allows only administrators to read and write business data if they are an admin of the business or if the business does not yet exist\r\n      \"$business_id\": {\r\n        \".write\": \"!data.exists() || (root.child('employees/' + auth.uid + '/business').val() === $business_id && root.child('employees/' + auth.uid + '/role').val() === 99)\"\r\n      }\r\n```\r\n\r\nHere's a the model for `business`:\r\n\r\n```javascript\r\nexport default DS.Model.extend({\r\n  name: DS.attr('string'),\r\n  employees: DS.hasMany('employee', { async: true })\r\n});\r\n```\r\n\r\nWhat I'm seeing is that the `employee` is being properly written to Firebase, but then I'm seeing an access denied error such as `FIREBASE WARNING: update at /businesses/-JnQNYZm_3gfB8L72i4d failed: permission_denied` and the `name` of the business is not being written. However, if I remove the rule completely and allow all anyone to write to it, both the `name` and `employee` are both written. It's almost like the relationship is being persisted to the server in one call and then other properties are persisted in another call, which would explain why I'm seeing the `employee` property being persisted, given the rule I've defined above.\r\n\r\nAny insights?\r\n\r\nBest,\r\nJames"},"comment":{"url":"https://api.github.com/repos/firebase/emberfire/issues/comments/95358927","html_url":"https://github.com/firebase/emberfire/issues/246#issuecomment-95358927","issue_url":"https://api.github.com/repos/firebase/emberfire/issues/246","id":95358927,"user":{"login":"tstirrat","id":702990,"avatar_url":"https://avatars.githubusercontent.com/u/702990?v=3","gravatar_id":"","url":"https://api.github.com/users/tstirrat","html_url":"https://github.com/tstirrat","followers_url":"https://api.github.com/users/tstirrat/followers","following_url":"https://api.github.com/users/tstirrat/following{/other_user}","gists_url":"https://api.github.com/users/tstirrat/gists{/gist_id}","starred_url":"https://api.github.com/users/tstirrat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tstirrat/subscriptions","organizations_url":"https://api.github.com/users/tstirrat/orgs","repos_url":"https://api.github.com/users/tstirrat/repos","events_url":"https://api.github.com/users/tstirrat/events{/privacy}","received_events_url":"https://api.github.com/users/tstirrat/received_events","type":"User","site_admin":false},"created_at":"2015-04-22T22:47:02Z","updated_at":"2015-04-22T22:47:02Z","body":"Hi James,\r\n\r\nYes, there are two writes, the record and the `hasMany` relationship links are written in two steps (see in the code [here](https://github.com/firebase/emberfire/blob/v1.4.4/addon/adapters/firebase.js#L354-L369))\r\n\r\nI believe this was to get around an issue of two clients trying to change `hasMany` links concurrently.\r\n\r\nUnfortunately, it makes it difficult to do what you're trying to achieve. I'm brainstorming some ideas for a workaround.. "}}