{"action":"created","comment":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/comments/32719608","id":32719608,"diff_hunk":"@@ -1225,6 +1424,52 @@ module.exports = function(dataSource, should) {\n           });\n       });\n \n+      it('triggers `loaded` hook on create', function(done) {\n+        TestModel.observe('loaded', pushContextAndNext());\n+\n+        TestModel.updateOrCreate(\n+          { id: 'new-id', name: 'a name' },\n+          function(err, instance) {\n+            if (err) return done(err);\n+\n+            if (dataSource.connector.updateOrCreate) {\n+              observedContexts.should.eql(aTestModelCtx({\n+                data: { id: 'new-id', name: 'a name' }\n+              }));\n+            } else {\n+              observedContexts.should.eql(aTestModelCtx({\n+                data: {\n+                  id: 'new-id',\n+                  name: 'a name'\n+                },\n+                isNewInstance: true\n+              }));\n+            }\n+            done();\n+          });\n+      });\n+\n+      // TODO (pradnya) - Here for Unoptimized connector, \n+      // `pushContextAndNext` is getting called twice. As a result, observedContexts\n+      // returns an array and NOT a single instance.\n+      // Optimized connector, works as expected.","path":"test/persistence-hooks.suite.js","position":273,"original_position":273,"commit_id":"1552fc47cd1adae505b7f43d0441df09312b9adb","original_commit_id":"1552fc47cd1adae505b7f43d0441df09312b9adb","user":{"login":"bajtos","id":1140553,"avatar_url":"https://avatars.githubusercontent.com/u/1140553?v=3","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"body":"I think that's expected because the unoptimized connector calls to operations: \"find\" and \"create\", both of them call the \"loaded\" hook. I am proposing to modify the assertion depending on which connector is being used.\r\n\r\n```js\r\nif (connector.updateOrCreate) {\r\n  // assert observedContext is a single item\r\n} else {\r\n  // assert observedContext is an array\r\n}\r\n```\r\n\r\nThoughts?","created_at":"2015-06-18T11:13:24Z","updated_at":"2015-06-18T11:13:24Z","html_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/599#discussion_r32719608","pull_request_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/599","_links":{"self":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/comments/32719608"},"html":{"href":"https://github.com/strongloop/loopback-datasource-juggler/pull/599#discussion_r32719608"},"pull_request":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/599"}}},"pull_request":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/599","id":35926228,"html_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/599","diff_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/599.diff","patch_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/599.patch","issue_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/599","number":599,"state":"open","locked":false,"title":"Add new hook 'loaded'","user":{"login":"PradnyaBaviskar","id":10217160,"avatar_url":"https://avatars.githubusercontent.com/u/10217160?v=3","gravatar_id":"","url":"https://api.github.com/users/PradnyaBaviskar","html_url":"https://github.com/PradnyaBaviskar","followers_url":"https://api.github.com/users/PradnyaBaviskar/followers","following_url":"https://api.github.com/users/PradnyaBaviskar/following{/other_user}","gists_url":"https://api.github.com/users/PradnyaBaviskar/gists{/gist_id}","starred_url":"https://api.github.com/users/PradnyaBaviskar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PradnyaBaviskar/subscriptions","organizations_url":"https://api.github.com/users/PradnyaBaviskar/orgs","repos_url":"https://api.github.com/users/PradnyaBaviskar/repos","events_url":"https://api.github.com/users/PradnyaBaviskar/events{/privacy}","received_events_url":"https://api.github.com/users/PradnyaBaviskar/received_events","type":"User","site_admin":false},"body":"Connect to #441\r\n\r\n/to @raymondfeng, can you please review?\r\n/cc @bajtos  ","created_at":"2015-05-21T11:58:20Z","updated_at":"2015-06-18T11:13:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"41e08d7a2b904ac5abe3ea4f1573ace328698112","assignee":{"login":"bajtos","id":1140553,"avatar_url":"https://avatars.githubusercontent.com/u/1140553?v=3","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/599/commits","review_comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/599/comments","review_comment_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/599/comments","statuses_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/statuses/1552fc47cd1adae505b7f43d0441df09312b9adb","head":{"label":"PradnyaBaviskar:issue-441","ref":"issue-441","sha":"1552fc47cd1adae505b7f43d0441df09312b9adb","user":{"login":"PradnyaBaviskar","id":10217160,"avatar_url":"https://avatars.githubusercontent.com/u/10217160?v=3","gravatar_id":"","url":"https://api.github.com/users/PradnyaBaviskar","html_url":"https://github.com/PradnyaBaviskar","followers_url":"https://api.github.com/users/PradnyaBaviskar/followers","following_url":"https://api.github.com/users/PradnyaBaviskar/following{/other_user}","gists_url":"https://api.github.com/users/PradnyaBaviskar/gists{/gist_id}","starred_url":"https://api.github.com/users/PradnyaBaviskar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PradnyaBaviskar/subscriptions","organizations_url":"https://api.github.com/users/PradnyaBaviskar/orgs","repos_url":"https://api.github.com/users/PradnyaBaviskar/repos","events_url":"https://api.github.com/users/PradnyaBaviskar/events{/privacy}","received_events_url":"https://api.github.com/users/PradnyaBaviskar/received_events","type":"User","site_admin":false},"repo":{"id":30293626,"name":"loopback-datasource-juggler","full_name":"PradnyaBaviskar/loopback-datasource-juggler","owner":{"login":"PradnyaBaviskar","id":10217160,"avatar_url":"https://avatars.githubusercontent.com/u/10217160?v=3","gravatar_id":"","url":"https://api.github.com/users/PradnyaBaviskar","html_url":"https://github.com/PradnyaBaviskar","followers_url":"https://api.github.com/users/PradnyaBaviskar/followers","following_url":"https://api.github.com/users/PradnyaBaviskar/following{/other_user}","gists_url":"https://api.github.com/users/PradnyaBaviskar/gists{/gist_id}","starred_url":"https://api.github.com/users/PradnyaBaviskar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PradnyaBaviskar/subscriptions","organizations_url":"https://api.github.com/users/PradnyaBaviskar/orgs","repos_url":"https://api.github.com/users/PradnyaBaviskar/repos","events_url":"https://api.github.com/users/PradnyaBaviskar/events{/privacy}","received_events_url":"https://api.github.com/users/PradnyaBaviskar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/PradnyaBaviskar/loopback-datasource-juggler","description":"Connect Loopback to various Data Sources","fork":true,"url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler","forks_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/forks","keys_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/teams","hooks_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/hooks","issue_events_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/issues/events{/number}","events_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/events","assignees_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/assignees{/user}","branches_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/branches{/branch}","tags_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/tags","blobs_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/git/refs{/sha}","trees_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/statuses/{sha}","languages_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/languages","stargazers_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/stargazers","contributors_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/contributors","subscribers_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/subscribers","subscription_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/subscription","commits_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/commits{/sha}","git_commits_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/git/commits{/sha}","comments_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/comments{/number}","issue_comment_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/issues/comments{/number}","contents_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/contents/{+path}","compare_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/merges","archive_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/downloads","issues_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/issues{/number}","pulls_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/pulls{/number}","milestones_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/milestones{/number}","notifications_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/labels{/name}","releases_url":"https://api.github.com/repos/PradnyaBaviskar/loopback-datasource-juggler/releases{/id}","created_at":"2015-02-04T10:30:22Z","updated_at":"2015-05-08T06:23:45Z","pushed_at":"2015-06-18T10:43:46Z","git_url":"git://github.com/PradnyaBaviskar/loopback-datasource-juggler.git","ssh_url":"git@github.com:PradnyaBaviskar/loopback-datasource-juggler.git","clone_url":"https://github.com/PradnyaBaviskar/loopback-datasource-juggler.git","svn_url":"https://github.com/PradnyaBaviskar/loopback-datasource-juggler","homepage":"www.strongloop.com","size":4646,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"strongloop:master","ref":"master","sha":"019705d32f9f6cff2ccca856214ad20854f46af9","user":{"login":"strongloop","id":3020012,"avatar_url":"https://avatars.githubusercontent.com/u/3020012?v=3","gravatar_id":"","url":"https://api.github.com/users/strongloop","html_url":"https://github.com/strongloop","followers_url":"https://api.github.com/users/strongloop/followers","following_url":"https://api.github.com/users/strongloop/following{/other_user}","gists_url":"https://api.github.com/users/strongloop/gists{/gist_id}","starred_url":"https://api.github.com/users/strongloop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongloop/subscriptions","organizations_url":"https://api.github.com/users/strongloop/orgs","repos_url":"https://api.github.com/users/strongloop/repos","events_url":"https://api.github.com/users/strongloop/events{/privacy}","received_events_url":"https://api.github.com/users/strongloop/received_events","type":"Organization","site_admin":false},"repo":{"id":10126908,"name":"loopback-datasource-juggler","full_name":"strongloop/loopback-datasource-juggler","owner":{"login":"strongloop","id":3020012,"avatar_url":"https://avatars.githubusercontent.com/u/3020012?v=3","gravatar_id":"","url":"https://api.github.com/users/strongloop","html_url":"https://github.com/strongloop","followers_url":"https://api.github.com/users/strongloop/followers","following_url":"https://api.github.com/users/strongloop/following{/other_user}","gists_url":"https://api.github.com/users/strongloop/gists{/gist_id}","starred_url":"https://api.github.com/users/strongloop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongloop/subscriptions","organizations_url":"https://api.github.com/users/strongloop/orgs","repos_url":"https://api.github.com/users/strongloop/repos","events_url":"https://api.github.com/users/strongloop/events{/privacy}","received_events_url":"https://api.github.com/users/strongloop/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/strongloop/loopback-datasource-juggler","description":"Connect Loopback to various Data Sources","fork":false,"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler","forks_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/forks","keys_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/teams","hooks_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/hooks","issue_events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/events{/number}","events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/events","assignees_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/assignees{/user}","branches_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/branches{/branch}","tags_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/tags","blobs_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/refs{/sha}","trees_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/statuses/{sha}","languages_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/languages","stargazers_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/stargazers","contributors_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/contributors","subscribers_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/subscribers","subscription_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/subscription","commits_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/commits{/sha}","git_commits_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/commits{/sha}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/comments{/number}","issue_comment_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/comments{/number}","contents_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/contents/{+path}","compare_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/merges","archive_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/downloads","issues_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues{/number}","pulls_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls{/number}","milestones_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/milestones{/number}","notifications_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels{/name}","releases_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/releases{/id}","created_at":"2013-05-17T15:56:04Z","updated_at":"2015-06-18T01:40:17Z","pushed_at":"2015-06-18T10:43:46Z","git_url":"git://github.com/strongloop/loopback-datasource-juggler.git","ssh_url":"git@github.com:strongloop/loopback-datasource-juggler.git","clone_url":"https://github.com/strongloop/loopback-datasource-juggler.git","svn_url":"https://github.com/strongloop/loopback-datasource-juggler","homepage":"www.strongloop.com","size":10083,"stargazers_count":75,"watchers_count":75,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":78,"mirror_url":null,"open_issues_count":136,"forks":78,"open_issues":136,"watchers":75,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/599"},"html":{"href":"https://github.com/strongloop/loopback-datasource-juggler/pull/599"},"issue":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/599"},"comments":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/599/comments"},"review_comments":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/599/comments"},"review_comment":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/599/commits"},"statuses":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/statuses/1552fc47cd1adae505b7f43d0441df09312b9adb"}}}}