{"action":"created","comment":{"url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/comments/25602697","id":25602697,"diff_hunk":"@@ -0,0 +1,438 @@\n+/**\n+ * Module dependencies\n+ */\n+\n+var _ = require( 'lodash' ),\n+\tutil = require( 'util' );\n+\n+// Parameter used for jsonp callback is constant, as far as\n+// blueprints are concerned (for now.)\n+var JSONP_CALLBACK_PARAM = 'callback';\n+\n+/**\n+ * Utility methods used in built-in blueprint actions.\n+ *\n+ * @type {Object}\n+ */\n+module.exports = {\n+\n+\t/**\n+\t * Extend the model's `associations` property with the presentation configuration (taken from the Model's attributes `includeIn` option or from Sails configuration)\n+\t * @param  {Waterline Collection}  Model\n+\t * @return {Array}                 Extended version of the Model.associations with `includeIn` defintions\n+\t */\n+\tgetAssociationConfiguration: function ( Model, style ) {\n+\t\t// get configured defaults or always embed full records\n+\t\tvar presentationDefaults = sails.config.models.associations || {\n+\t\t\tlist: \"record\",\n+\t\t\tdetail: \"record\"\n+\t\t};\n+\t\tvar associations = Model.associations;\n+\t\tvar attributes = Model._attributes;\n+\t\t_.each( associations, function ( assoc ) {\n+\t\t\tassoc.include = _.extend( {}, presentationDefaults, attributes[ assoc.alias ].includeIn )[ style ]; // extend association object with presentation configuration\n+\t\t\tif ( attributes[ assoc.alias ].through ) {\n+\t\t\t\tassoc.through = attributes[ assoc.alias ].through;\n+\t\t\t}\n+\t\t} );\n+\t\treturn associations;\n+\t},\n+\n+\t/**\n+\t * AccessControl proxy function, expects a Waterline query object for before* hooks and an array of records for after* hooks.\n+\t * @param  {Collection} model             Waterline collectio, from parseModel\n+\t * @param  {String} action                blueprint or hook, e.g. beforeFind, afterFind, beforeCreate, afterCreate --> translates to accessControlBeforeFind, etc.\n+\t * @param  {Object} options               Options: query {Query} Waterline query object for before* hooks, records: {Array} records for after* hooks, {Model} current user record\n+\t * @return {Query|Array}                  returns the modified query (with altered criteria) for before* or the filtered/extended record array for after*.\n+\t */\n+\taccessControl: function ( model, action, options, callback ) {\n+\t\tvar primaryArgument = null;\n+\t\tvar capitaliseFirstLetter = function ( string ) {\n+\t\t\treturn string.charAt( 0 ).toUpperCase() + string.slice( 1 );\n+\t\t};\n+\n+\t\tif ( action.indexOf( \"before\" ) === 0 ) {\n+\t\t\tif ( !options.criteria ) throw new Error( \"accessControl before* hook needs option: criteria!\" );\n+\t\t\tprimaryArgument = options.criteria;\n+\t\t} else if ( action.indexOf( \"after\" ) === 0 ) { // turns out that access control after querying the database is a bad idea, because counting and pagination patterns are broken\n+\t\t\tif ( !options.records ) throw new Error( \"accessControl after* hook needs option: records!\" );\n+\t\t\tprimaryArgument = options.records;\n+\t\t} else {\n+\t\t\tthrow new Error( \"accessControl action '\" + action + \"' doesn't fit into before/after pattern.\" );\n+\t\t}\n+\n+\t\taction = capitaliseFirstLetter( action );\n+\n+\t\tif ( typeof model[ \"control\" + action ] === \"function\" ) {\n+\t\t\tprimaryArgument = model[ \"control\" + action ]( primaryArgument, options, callback );\n+\t\t} else {\n+\t\t\tconsole.log( \"Dev: Model \" + model.identity + \" is missing control \" + action + \"!\" );\n+\t\t\tif ( callback ) {\n+\t\t\t\tcallback( null, primaryArgument );\n+\t\t\t}\n+\t\t}\n+\t\treturn primaryArgument;\n+\t},\n+\n+\t/**\n+\t * helper function to populate a record with an array for indexes for associated models, running various Waterline queries on the join tables if neccessary ( defined as: include -> index )\n+\t * @param  {Waterine Collection}   parentModel  [description]\n+\t * @param  {Array|Integer}   ids          [description]\n+\t * @param  {[type]}   associations [description]\n+\t * @param  {Function} done         [description]\n+\t */\n+\tpopulateIndexes: function ( parentModel, ids, associations, done ) {","path":"templates/advanced/api/blueprints/_util/actionUtil.js","position":84,"original_position":84,"commit_id":"066304d688a3458c359a836fe5360a2b524f9164","original_commit_id":"066304d688a3458c359a836fe5360a2b524f9164","user":{"login":"mphasize","id":331830,"avatar_url":"https://avatars.githubusercontent.com/u/331830?v=3","gravatar_id":"","url":"https://api.github.com/users/mphasize","html_url":"https://github.com/mphasize","followers_url":"https://api.github.com/users/mphasize/followers","following_url":"https://api.github.com/users/mphasize/following{/other_user}","gists_url":"https://api.github.com/users/mphasize/gists{/gist_id}","starred_url":"https://api.github.com/users/mphasize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mphasize/subscriptions","organizations_url":"https://api.github.com/users/mphasize/orgs","repos_url":"https://api.github.com/users/mphasize/repos","events_url":"https://api.github.com/users/mphasize/events{/privacy}","received_events_url":"https://api.github.com/users/mphasize/received_events","type":"User","site_admin":false},"body":"Can anybody verify that this method runs as expected on a Mongo/NoSQL database? (It's used in `find` and `findOne` blueprints). Set sideloading to `index` to enable this.","created_at":"2015-03-02T14:47:39Z","updated_at":"2015-03-02T14:47:39Z","html_url":"https://github.com/mphasize/sails-generate-ember-blueprints/pull/9#discussion_r25602697","pull_request_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/comments/25602697"},"html":{"href":"https://github.com/mphasize/sails-generate-ember-blueprints/pull/9#discussion_r25602697"},"pull_request":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/9","id":29600391,"html_url":"https://github.com/mphasize/sails-generate-ember-blueprints/pull/9","diff_url":"https://github.com/mphasize/sails-generate-ember-blueprints/pull/9.diff","patch_url":"https://github.com/mphasize/sails-generate-ember-blueprints/pull/9.patch","issue_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues/9","number":9,"state":"open","locked":false,"title":"WIP: A more sophisticated set of blueprints","user":{"login":"mphasize","id":331830,"avatar_url":"https://avatars.githubusercontent.com/u/331830?v=3","gravatar_id":"","url":"https://api.github.com/users/mphasize","html_url":"https://github.com/mphasize","followers_url":"https://api.github.com/users/mphasize/followers","following_url":"https://api.github.com/users/mphasize/following{/other_user}","gists_url":"https://api.github.com/users/mphasize/gists{/gist_id}","starred_url":"https://api.github.com/users/mphasize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mphasize/subscriptions","organizations_url":"https://api.github.com/users/mphasize/orgs","repos_url":"https://api.github.com/users/mphasize/repos","events_url":"https://api.github.com/users/mphasize/events{/privacy}","received_events_url":"https://api.github.com/users/mphasize/received_events","type":"User","site_admin":false},"body":"Hej, I've been working on an \"advanced\" set of blueprints for some time now and I think it's time to discuss this.\r\n\r\nAs a preparation I enabled the generator to support different \"flavors\" of blueprints and I'm keeping the original blueprints around as a \"basic\" flavor and added the new blueprints as an \"advanced\" flavor.\r\n\r\nSo what do these new blueprints do?\r\n- enable full control on how the API REST handles associations/relationships: **url links**, **indexing** and **sideloading** supported.\r\n- add `meta` information to `find` queries, which enable **pagination** on the client side\r\n\r\nWhat needs to be done?\r\n- [x] remove the need to install `lodash` and `pluralize` as separate dependencies\r\n- [x] update blueprints with latest fixes from Sails v0.11\r\n- [x] add the camelCase fix for sideloaded association names in the JSON output\r\n- [x] gather some feedback from the community: does this work/feel right? maybe some better naming for configuration options?\r\n- [ ] test how this works on Mongo/NoSQL databases\r\n- [x] optimized performance of the **index** option on Many-to-Many relationships, i.e. on SQL we can just load the indexes from the join table without actually performing a full join.\r\n- [ ] add some tests, for example if proper configuration options are set\r\n- [ ] add examples and explain all the configuration options and their impact\r\n\r\nHappy to get some feedback on this and do some further planning...","created_at":"2015-02-19T10:31:30Z","updated_at":"2015-03-02T14:47:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c878d197b284f4436a28fa491617bb632be62ecf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/9/commits","review_comments_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/9/comments","review_comment_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues/9/comments","statuses_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/statuses/066304d688a3458c359a836fe5360a2b524f9164","head":{"label":"mphasize:advanced","ref":"advanced","sha":"066304d688a3458c359a836fe5360a2b524f9164","user":{"login":"mphasize","id":331830,"avatar_url":"https://avatars.githubusercontent.com/u/331830?v=3","gravatar_id":"","url":"https://api.github.com/users/mphasize","html_url":"https://github.com/mphasize","followers_url":"https://api.github.com/users/mphasize/followers","following_url":"https://api.github.com/users/mphasize/following{/other_user}","gists_url":"https://api.github.com/users/mphasize/gists{/gist_id}","starred_url":"https://api.github.com/users/mphasize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mphasize/subscriptions","organizations_url":"https://api.github.com/users/mphasize/orgs","repos_url":"https://api.github.com/users/mphasize/repos","events_url":"https://api.github.com/users/mphasize/events{/privacy}","received_events_url":"https://api.github.com/users/mphasize/received_events","type":"User","site_admin":false},"repo":{"id":24419942,"name":"sails-generate-ember-blueprints","full_name":"mphasize/sails-generate-ember-blueprints","owner":{"login":"mphasize","id":331830,"avatar_url":"https://avatars.githubusercontent.com/u/331830?v=3","gravatar_id":"","url":"https://api.github.com/users/mphasize","html_url":"https://github.com/mphasize","followers_url":"https://api.github.com/users/mphasize/followers","following_url":"https://api.github.com/users/mphasize/following{/other_user}","gists_url":"https://api.github.com/users/mphasize/gists{/gist_id}","starred_url":"https://api.github.com/users/mphasize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mphasize/subscriptions","organizations_url":"https://api.github.com/users/mphasize/orgs","repos_url":"https://api.github.com/users/mphasize/repos","events_url":"https://api.github.com/users/mphasize/events{/privacy}","received_events_url":"https://api.github.com/users/mphasize/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mphasize/sails-generate-ember-blueprints","description":"Generate Ember Data DS.RESTAdapter compatible blueprints","fork":false,"url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints","forks_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/forks","keys_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/teams","hooks_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/hooks","issue_events_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues/events{/number}","events_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/events","assignees_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/assignees{/user}","branches_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/branches{/branch}","tags_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/tags","blobs_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/refs{/sha}","trees_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/statuses/{sha}","languages_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/languages","stargazers_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/stargazers","contributors_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/contributors","subscribers_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/subscribers","subscription_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/subscription","commits_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/commits{/sha}","git_commits_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/commits{/sha}","comments_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/comments{/number}","issue_comment_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues/comments{/number}","contents_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/contents/{+path}","compare_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/merges","archive_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/downloads","issues_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues{/number}","pulls_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls{/number}","milestones_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/milestones{/number}","notifications_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/labels{/name}","releases_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/releases{/id}","created_at":"2014-09-24T15:09:48Z","updated_at":"2015-03-01T21:45:45Z","pushed_at":"2015-03-02T13:54:05Z","git_url":"git://github.com/mphasize/sails-generate-ember-blueprints.git","ssh_url":"git@github.com:mphasize/sails-generate-ember-blueprints.git","clone_url":"https://github.com/mphasize/sails-generate-ember-blueprints.git","svn_url":"https://github.com/mphasize/sails-generate-ember-blueprints","homepage":null,"size":512,"stargazers_count":21,"watchers_count":21,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":6,"forks":4,"open_issues":6,"watchers":21,"default_branch":"master"}},"base":{"label":"mphasize:master","ref":"master","sha":"68243df0771e750e268f6b0ac404d730596d6d63","user":{"login":"mphasize","id":331830,"avatar_url":"https://avatars.githubusercontent.com/u/331830?v=3","gravatar_id":"","url":"https://api.github.com/users/mphasize","html_url":"https://github.com/mphasize","followers_url":"https://api.github.com/users/mphasize/followers","following_url":"https://api.github.com/users/mphasize/following{/other_user}","gists_url":"https://api.github.com/users/mphasize/gists{/gist_id}","starred_url":"https://api.github.com/users/mphasize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mphasize/subscriptions","organizations_url":"https://api.github.com/users/mphasize/orgs","repos_url":"https://api.github.com/users/mphasize/repos","events_url":"https://api.github.com/users/mphasize/events{/privacy}","received_events_url":"https://api.github.com/users/mphasize/received_events","type":"User","site_admin":false},"repo":{"id":24419942,"name":"sails-generate-ember-blueprints","full_name":"mphasize/sails-generate-ember-blueprints","owner":{"login":"mphasize","id":331830,"avatar_url":"https://avatars.githubusercontent.com/u/331830?v=3","gravatar_id":"","url":"https://api.github.com/users/mphasize","html_url":"https://github.com/mphasize","followers_url":"https://api.github.com/users/mphasize/followers","following_url":"https://api.github.com/users/mphasize/following{/other_user}","gists_url":"https://api.github.com/users/mphasize/gists{/gist_id}","starred_url":"https://api.github.com/users/mphasize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mphasize/subscriptions","organizations_url":"https://api.github.com/users/mphasize/orgs","repos_url":"https://api.github.com/users/mphasize/repos","events_url":"https://api.github.com/users/mphasize/events{/privacy}","received_events_url":"https://api.github.com/users/mphasize/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mphasize/sails-generate-ember-blueprints","description":"Generate Ember Data DS.RESTAdapter compatible blueprints","fork":false,"url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints","forks_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/forks","keys_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/teams","hooks_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/hooks","issue_events_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues/events{/number}","events_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/events","assignees_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/assignees{/user}","branches_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/branches{/branch}","tags_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/tags","blobs_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/refs{/sha}","trees_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/statuses/{sha}","languages_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/languages","stargazers_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/stargazers","contributors_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/contributors","subscribers_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/subscribers","subscription_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/subscription","commits_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/commits{/sha}","git_commits_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/git/commits{/sha}","comments_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/comments{/number}","issue_comment_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues/comments{/number}","contents_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/contents/{+path}","compare_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/merges","archive_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/downloads","issues_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues{/number}","pulls_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls{/number}","milestones_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/milestones{/number}","notifications_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/labels{/name}","releases_url":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/releases{/id}","created_at":"2014-09-24T15:09:48Z","updated_at":"2015-03-01T21:45:45Z","pushed_at":"2015-03-02T13:54:05Z","git_url":"git://github.com/mphasize/sails-generate-ember-blueprints.git","ssh_url":"git@github.com:mphasize/sails-generate-ember-blueprints.git","clone_url":"https://github.com/mphasize/sails-generate-ember-blueprints.git","svn_url":"https://github.com/mphasize/sails-generate-ember-blueprints","homepage":null,"size":512,"stargazers_count":21,"watchers_count":21,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":6,"forks":4,"open_issues":6,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/9"},"html":{"href":"https://github.com/mphasize/sails-generate-ember-blueprints/pull/9"},"issue":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues/9"},"comments":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/mphasize/sails-generate-ember-blueprints/statuses/066304d688a3458c359a836fe5360a2b524f9164"}}}}