{"action":"created","issue":{"url":"https://api.github.com/repos/jmdobry/angular-data/issues/281","labels_url":"https://api.github.com/repos/jmdobry/angular-data/issues/281/labels{/name}","comments_url":"https://api.github.com/repos/jmdobry/angular-data/issues/281/comments","events_url":"https://api.github.com/repos/jmdobry/angular-data/issues/281/events","html_url":"https://github.com/jmdobry/angular-data/issues/281","id":53465882,"number":281,"title":"Relations - belongsTo same localField and localKey","user":{"login":"JetFault","id":487245,"avatar_url":"https://avatars.githubusercontent.com/u/487245?v=3","gravatar_id":"","url":"https://api.github.com/users/JetFault","html_url":"https://github.com/JetFault","followers_url":"https://api.github.com/users/JetFault/followers","following_url":"https://api.github.com/users/JetFault/following{/other_user}","gists_url":"https://api.github.com/users/JetFault/gists{/gist_id}","starred_url":"https://api.github.com/users/JetFault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JetFault/subscriptions","organizations_url":"https://api.github.com/users/JetFault/orgs","repos_url":"https://api.github.com/users/JetFault/repos","events_url":"https://api.github.com/users/JetFault/events{/privacy}","received_events_url":"https://api.github.com/users/JetFault/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jmdobry/angular-data/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-01-06T00:24:21Z","updated_at":"2015-01-07T19:44:35Z","closed_at":"2015-01-07T15:02:22Z","body":"I'm using Sails on the backend. The API returns: \r\n```\r\n{\r\n  id: 3,\r\n  jobs: [\r\n    {\r\n      id: 4,\r\n      user: 3\r\n    }\r\n  ]\r\n}\r\n```\r\nSo the user obj will be returned with the loaded jobs. However, when looking at angular data, it tries to recursively inject all relations, so it would try to inject the `user` field in the job. This would wind up calling a `DS.inject('user', 3)` which is not a valid inject call cause `attrs` is required to be an object/array, however it is a number. The reason this seems to happen is because `localField` and `localKey` are the same. However, Sails populates associations onto the model, so populating the user onto a job would return:\r\n```\r\n{\r\n  id: 4,\r\n  user: {\r\n    id: 3\r\n  }\r\n}\r\n```\r\nWhile a not populated call would return:\r\n```\r\n{\r\n  id: 4,\r\n  user: 3\r\n}\r\n```\r\nSo, localField and localKey would have to be the same.\r\n\r\nHere is a plunker to show the issue: http://plnkr.co/edit/NxXdAnuwBUzDyY2X9u2Z?p=preview\r\nHowever, since angular-mock is used, the logs that angular-data is using aren't showing.\r\n\r\nThere should probably be a check to see if localField is not an object, to just not insert it?"},"comment":{"url":"https://api.github.com/repos/jmdobry/angular-data/issues/comments/69079517","html_url":"https://github.com/jmdobry/angular-data/issues/281#issuecomment-69079517","issue_url":"https://api.github.com/repos/jmdobry/angular-data/issues/281","id":69079517,"user":{"login":"JetFault","id":487245,"avatar_url":"https://avatars.githubusercontent.com/u/487245?v=3","gravatar_id":"","url":"https://api.github.com/users/JetFault","html_url":"https://github.com/JetFault","followers_url":"https://api.github.com/users/JetFault/followers","following_url":"https://api.github.com/users/JetFault/following{/other_user}","gists_url":"https://api.github.com/users/JetFault/gists{/gist_id}","starred_url":"https://api.github.com/users/JetFault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JetFault/subscriptions","organizations_url":"https://api.github.com/users/JetFault/orgs","repos_url":"https://api.github.com/users/JetFault/repos","events_url":"https://api.github.com/users/JetFault/events{/privacy}","received_events_url":"https://api.github.com/users/JetFault/received_events","type":"User","site_admin":false},"created_at":"2015-01-07T19:44:35Z","updated_at":"2015-01-07T19:44:35Z","body":"Is there any way to make this work for `DS.inject`, I inject whenever I get data from sockets/cached data in DOM?\r\n\r\nAlso, wondering the use case of localKey/Field? To see if it is possible to just not call inject for relations if localField is not an object. https://github.com/jmdobry/angular-data/blob/master/src/datastore/sync_methods/inject.js#L19"}}