{"action":"created","comment":{"url":"https://api.github.com/repos/Aloompa/cannery/pulls/comments/55575027","id":55575027,"diff_hunk":"@@ -40,40 +36,107 @@ class OwnsMany extends MultiModel {\n         }\n \n         model.getAdapter().fetch(model, options, (response) => {\n-            model.apply(response);\n+            this.apply([response]);\n+            this.emit('change');\n         });\n \n         return model;\n     }\n \n-    requestMany (options: ?Object) {\n+    // @override\n+    requestMany (options: Object = {}): any {\n         const model = this._instantiateModel();\n \n         model\n             .getAdapter()\n             .findAll(this.Model, this._parent, options, (response) => {\n-                this.apply(response, options);\n+                this.apply(response);\n+                this.applyQueryResults(response, options);\n+                this.emit('change');\n             });\n+\n+        return this;\n     }\n \n-    apply (data : Array<Object>) {\n+    apply (data : Array<Object>): Object {\n         data.forEach((item) => {\n-            const model = this._instantiateModel();\n+            this._models[item.id] = this._models[item.id] || this._instantiateModel();\n+            this._models[item.id].apply(item);\n+        });\n+\n+        return this;\n+    }\n+\n+    applyQueryResults (data : Array<Object>, options: Object = {}): Object {\n+        const idKey = this.Model.getFieldId();\n \n-            this._models[item.id] = model;\n-            model.apply(item);\n+        if (!Array.isArray(data)) {\n+            data = [];\n+        }\n+\n+        const ids = data.map((modelData) => {\n+            return modelData[idKey];\n         });\n+\n+        this.requestCache.set(options, ids);\n+\n+        return this;\n+    }\n+\n+    all (): Array<Object> {\n+        if (Object.keys(this._models).length) {\n+\n+            // Mapped owns many\n+            if (this.map) {\n+                return this.map.map((id) => {\n+                    return this._models[id];\n+                });\n+            }\n+\n+            // Unmapped\n+            return Object.keys(this._models).map((id) => {\n+                return this._models[id];\n+            });\n+        }\n+\n+        this.requestMany({});\n+        return [];\n     }\n \n     toJSON (options : Object = {}): any {\n         if (options.recursive) {\n-            return Object.keys(this._models).map((id) => {\n-                return this._models[id].toJSON(options);\n+            return this.all().map((model) => {\n+                return model.toJSON(options);\n+            });\n+        }\n+\n+        return [];\n+    }\n+\n+    query (options: Object = {}): Array<any> {\n+        let ids = this.requestCache.get(options);\n+\n+        if (ids) {\n+            const models = ids.map((id) => {\n+                return this._models[id];\n             });\n+\n+            const anyDestroyed = models.filter((model) => {\n+                return model.getState('isDestroyed');\n+            }).length;\n+\n+            if (!anyDestroyed) {\n+                return models;\n+            }\n         }\n \n+        this.requestMany(options);","path":"src/types/ownsMany.js","position":159,"original_position":159,"commit_id":"53d1083aad7bc9b5ac848c0a58f52c4525fd11cb","original_commit_id":"53d1083aad7bc9b5ac848c0a58f52c4525fd11cb","user":{"login":"peteigel","id":4098889,"avatar_url":"https://avatars.githubusercontent.com/u/4098889?v=3","gravatar_id":"","url":"https://api.github.com/users/peteigel","html_url":"https://github.com/peteigel","followers_url":"https://api.github.com/users/peteigel/followers","following_url":"https://api.github.com/users/peteigel/following{/other_user}","gists_url":"https://api.github.com/users/peteigel/gists{/gist_id}","starred_url":"https://api.github.com/users/peteigel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peteigel/subscriptions","organizations_url":"https://api.github.com/users/peteigel/orgs","repos_url":"https://api.github.com/users/peteigel/repos","events_url":"https://api.github.com/users/peteigel/events{/privacy}","received_events_url":"https://api.github.com/users/peteigel/received_events","type":"User","site_admin":false},"body":"This should be `{query: options}`","created_at":"2016-03-09T19:34:07Z","updated_at":"2016-03-09T19:34:07Z","html_url":"https://github.com/Aloompa/cannery/pull/18#discussion_r55575027","pull_request_url":"https://api.github.com/repos/Aloompa/cannery/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/Aloompa/cannery/pulls/comments/55575027"},"html":{"href":"https://github.com/Aloompa/cannery/pull/18#discussion_r55575027"},"pull_request":{"href":"https://api.github.com/repos/Aloompa/cannery/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/Aloompa/cannery/pulls/18","id":61572665,"html_url":"https://github.com/Aloompa/cannery/pull/18","diff_url":"https://github.com/Aloompa/cannery/pull/18.diff","patch_url":"https://github.com/Aloompa/cannery/pull/18.patch","issue_url":"https://api.github.com/repos/Aloompa/cannery/issues/18","number":18,"state":"open","locked":false,"title":"pefinished hasOne and ownsOne","user":{"login":"tysoncadenhead","id":355354,"avatar_url":"https://avatars.githubusercontent.com/u/355354?v=3","gravatar_id":"","url":"https://api.github.com/users/tysoncadenhead","html_url":"https://github.com/tysoncadenhead","followers_url":"https://api.github.com/users/tysoncadenhead/followers","following_url":"https://api.github.com/users/tysoncadenhead/following{/other_user}","gists_url":"https://api.github.com/users/tysoncadenhead/gists{/gist_id}","starred_url":"https://api.github.com/users/tysoncadenhead/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tysoncadenhead/subscriptions","organizations_url":"https://api.github.com/users/tysoncadenhead/orgs","repos_url":"https://api.github.com/users/tysoncadenhead/repos","events_url":"https://api.github.com/users/tysoncadenhead/events{/privacy}","received_events_url":"https://api.github.com/users/tysoncadenhead/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-03T15:10:25Z","updated_at":"2016-03-09T19:34:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ec033709ce2af2e80e9eec22f6dd8e4d0543efe7","assignee":{"login":"peteigel","id":4098889,"avatar_url":"https://avatars.githubusercontent.com/u/4098889?v=3","gravatar_id":"","url":"https://api.github.com/users/peteigel","html_url":"https://github.com/peteigel","followers_url":"https://api.github.com/users/peteigel/followers","following_url":"https://api.github.com/users/peteigel/following{/other_user}","gists_url":"https://api.github.com/users/peteigel/gists{/gist_id}","starred_url":"https://api.github.com/users/peteigel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peteigel/subscriptions","organizations_url":"https://api.github.com/users/peteigel/orgs","repos_url":"https://api.github.com/users/peteigel/repos","events_url":"https://api.github.com/users/peteigel/events{/privacy}","received_events_url":"https://api.github.com/users/peteigel/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Aloompa/cannery/pulls/18/commits","review_comments_url":"https://api.github.com/repos/Aloompa/cannery/pulls/18/comments","review_comment_url":"https://api.github.com/repos/Aloompa/cannery/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Aloompa/cannery/issues/18/comments","statuses_url":"https://api.github.com/repos/Aloompa/cannery/statuses/53d1083aad7bc9b5ac848c0a58f52c4525fd11cb","head":{"label":"Aloompa:feature/scope-tyson","ref":"feature/scope-tyson","sha":"53d1083aad7bc9b5ac848c0a58f52c4525fd11cb","user":{"login":"Aloompa","id":3011322,"avatar_url":"https://avatars.githubusercontent.com/u/3011322?v=3","gravatar_id":"","url":"https://api.github.com/users/Aloompa","html_url":"https://github.com/Aloompa","followers_url":"https://api.github.com/users/Aloompa/followers","following_url":"https://api.github.com/users/Aloompa/following{/other_user}","gists_url":"https://api.github.com/users/Aloompa/gists{/gist_id}","starred_url":"https://api.github.com/users/Aloompa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aloompa/subscriptions","organizations_url":"https://api.github.com/users/Aloompa/orgs","repos_url":"https://api.github.com/users/Aloompa/repos","events_url":"https://api.github.com/users/Aloompa/events{/privacy}","received_events_url":"https://api.github.com/users/Aloompa/received_events","type":"Organization","site_admin":false},"repo":{"id":47509393,"name":"cannery","full_name":"Aloompa/cannery","owner":{"login":"Aloompa","id":3011322,"avatar_url":"https://avatars.githubusercontent.com/u/3011322?v=3","gravatar_id":"","url":"https://api.github.com/users/Aloompa","html_url":"https://github.com/Aloompa","followers_url":"https://api.github.com/users/Aloompa/followers","following_url":"https://api.github.com/users/Aloompa/following{/other_user}","gists_url":"https://api.github.com/users/Aloompa/gists{/gist_id}","starred_url":"https://api.github.com/users/Aloompa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aloompa/subscriptions","organizations_url":"https://api.github.com/users/Aloompa/orgs","repos_url":"https://api.github.com/users/Aloompa/repos","events_url":"https://api.github.com/users/Aloompa/events{/privacy}","received_events_url":"https://api.github.com/users/Aloompa/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Aloompa/cannery","description":"An event-based JavaScript model layer","fork":false,"url":"https://api.github.com/repos/Aloompa/cannery","forks_url":"https://api.github.com/repos/Aloompa/cannery/forks","keys_url":"https://api.github.com/repos/Aloompa/cannery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Aloompa/cannery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Aloompa/cannery/teams","hooks_url":"https://api.github.com/repos/Aloompa/cannery/hooks","issue_events_url":"https://api.github.com/repos/Aloompa/cannery/issues/events{/number}","events_url":"https://api.github.com/repos/Aloompa/cannery/events","assignees_url":"https://api.github.com/repos/Aloompa/cannery/assignees{/user}","branches_url":"https://api.github.com/repos/Aloompa/cannery/branches{/branch}","tags_url":"https://api.github.com/repos/Aloompa/cannery/tags","blobs_url":"https://api.github.com/repos/Aloompa/cannery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Aloompa/cannery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Aloompa/cannery/git/refs{/sha}","trees_url":"https://api.github.com/repos/Aloompa/cannery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Aloompa/cannery/statuses/{sha}","languages_url":"https://api.github.com/repos/Aloompa/cannery/languages","stargazers_url":"https://api.github.com/repos/Aloompa/cannery/stargazers","contributors_url":"https://api.github.com/repos/Aloompa/cannery/contributors","subscribers_url":"https://api.github.com/repos/Aloompa/cannery/subscribers","subscription_url":"https://api.github.com/repos/Aloompa/cannery/subscription","commits_url":"https://api.github.com/repos/Aloompa/cannery/commits{/sha}","git_commits_url":"https://api.github.com/repos/Aloompa/cannery/git/commits{/sha}","comments_url":"https://api.github.com/repos/Aloompa/cannery/comments{/number}","issue_comment_url":"https://api.github.com/repos/Aloompa/cannery/issues/comments{/number}","contents_url":"https://api.github.com/repos/Aloompa/cannery/contents/{+path}","compare_url":"https://api.github.com/repos/Aloompa/cannery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Aloompa/cannery/merges","archive_url":"https://api.github.com/repos/Aloompa/cannery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Aloompa/cannery/downloads","issues_url":"https://api.github.com/repos/Aloompa/cannery/issues{/number}","pulls_url":"https://api.github.com/repos/Aloompa/cannery/pulls{/number}","milestones_url":"https://api.github.com/repos/Aloompa/cannery/milestones{/number}","notifications_url":"https://api.github.com/repos/Aloompa/cannery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Aloompa/cannery/labels{/name}","releases_url":"https://api.github.com/repos/Aloompa/cannery/releases{/id}","deployments_url":"https://api.github.com/repos/Aloompa/cannery/deployments","created_at":"2015-12-06T19:00:00Z","updated_at":"2016-01-18T22:01:26Z","pushed_at":"2016-03-09T13:25:10Z","git_url":"git://github.com/Aloompa/cannery.git","ssh_url":"git@github.com:Aloompa/cannery.git","clone_url":"https://github.com/Aloompa/cannery.git","svn_url":"https://github.com/Aloompa/cannery","homepage":null,"size":260,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"Aloompa:release/scope","ref":"release/scope","sha":"5f294039c27f86e0f6aa1714b5a95cffdea5f55b","user":{"login":"Aloompa","id":3011322,"avatar_url":"https://avatars.githubusercontent.com/u/3011322?v=3","gravatar_id":"","url":"https://api.github.com/users/Aloompa","html_url":"https://github.com/Aloompa","followers_url":"https://api.github.com/users/Aloompa/followers","following_url":"https://api.github.com/users/Aloompa/following{/other_user}","gists_url":"https://api.github.com/users/Aloompa/gists{/gist_id}","starred_url":"https://api.github.com/users/Aloompa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aloompa/subscriptions","organizations_url":"https://api.github.com/users/Aloompa/orgs","repos_url":"https://api.github.com/users/Aloompa/repos","events_url":"https://api.github.com/users/Aloompa/events{/privacy}","received_events_url":"https://api.github.com/users/Aloompa/received_events","type":"Organization","site_admin":false},"repo":{"id":47509393,"name":"cannery","full_name":"Aloompa/cannery","owner":{"login":"Aloompa","id":3011322,"avatar_url":"https://avatars.githubusercontent.com/u/3011322?v=3","gravatar_id":"","url":"https://api.github.com/users/Aloompa","html_url":"https://github.com/Aloompa","followers_url":"https://api.github.com/users/Aloompa/followers","following_url":"https://api.github.com/users/Aloompa/following{/other_user}","gists_url":"https://api.github.com/users/Aloompa/gists{/gist_id}","starred_url":"https://api.github.com/users/Aloompa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aloompa/subscriptions","organizations_url":"https://api.github.com/users/Aloompa/orgs","repos_url":"https://api.github.com/users/Aloompa/repos","events_url":"https://api.github.com/users/Aloompa/events{/privacy}","received_events_url":"https://api.github.com/users/Aloompa/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Aloompa/cannery","description":"An event-based JavaScript model layer","fork":false,"url":"https://api.github.com/repos/Aloompa/cannery","forks_url":"https://api.github.com/repos/Aloompa/cannery/forks","keys_url":"https://api.github.com/repos/Aloompa/cannery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Aloompa/cannery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Aloompa/cannery/teams","hooks_url":"https://api.github.com/repos/Aloompa/cannery/hooks","issue_events_url":"https://api.github.com/repos/Aloompa/cannery/issues/events{/number}","events_url":"https://api.github.com/repos/Aloompa/cannery/events","assignees_url":"https://api.github.com/repos/Aloompa/cannery/assignees{/user}","branches_url":"https://api.github.com/repos/Aloompa/cannery/branches{/branch}","tags_url":"https://api.github.com/repos/Aloompa/cannery/tags","blobs_url":"https://api.github.com/repos/Aloompa/cannery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Aloompa/cannery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Aloompa/cannery/git/refs{/sha}","trees_url":"https://api.github.com/repos/Aloompa/cannery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Aloompa/cannery/statuses/{sha}","languages_url":"https://api.github.com/repos/Aloompa/cannery/languages","stargazers_url":"https://api.github.com/repos/Aloompa/cannery/stargazers","contributors_url":"https://api.github.com/repos/Aloompa/cannery/contributors","subscribers_url":"https://api.github.com/repos/Aloompa/cannery/subscribers","subscription_url":"https://api.github.com/repos/Aloompa/cannery/subscription","commits_url":"https://api.github.com/repos/Aloompa/cannery/commits{/sha}","git_commits_url":"https://api.github.com/repos/Aloompa/cannery/git/commits{/sha}","comments_url":"https://api.github.com/repos/Aloompa/cannery/comments{/number}","issue_comment_url":"https://api.github.com/repos/Aloompa/cannery/issues/comments{/number}","contents_url":"https://api.github.com/repos/Aloompa/cannery/contents/{+path}","compare_url":"https://api.github.com/repos/Aloompa/cannery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Aloompa/cannery/merges","archive_url":"https://api.github.com/repos/Aloompa/cannery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Aloompa/cannery/downloads","issues_url":"https://api.github.com/repos/Aloompa/cannery/issues{/number}","pulls_url":"https://api.github.com/repos/Aloompa/cannery/pulls{/number}","milestones_url":"https://api.github.com/repos/Aloompa/cannery/milestones{/number}","notifications_url":"https://api.github.com/repos/Aloompa/cannery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Aloompa/cannery/labels{/name}","releases_url":"https://api.github.com/repos/Aloompa/cannery/releases{/id}","deployments_url":"https://api.github.com/repos/Aloompa/cannery/deployments","created_at":"2015-12-06T19:00:00Z","updated_at":"2016-01-18T22:01:26Z","pushed_at":"2016-03-09T13:25:10Z","git_url":"git://github.com/Aloompa/cannery.git","ssh_url":"git@github.com:Aloompa/cannery.git","clone_url":"https://github.com/Aloompa/cannery.git","svn_url":"https://github.com/Aloompa/cannery","homepage":null,"size":260,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Aloompa/cannery/pulls/18"},"html":{"href":"https://github.com/Aloompa/cannery/pull/18"},"issue":{"href":"https://api.github.com/repos/Aloompa/cannery/issues/18"},"comments":{"href":"https://api.github.com/repos/Aloompa/cannery/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/Aloompa/cannery/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/Aloompa/cannery/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Aloompa/cannery/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/Aloompa/cannery/statuses/53d1083aad7bc9b5ac848c0a58f52c4525fd11cb"}}}}