{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/51996640","id":51996640,"diff_hunk":"@@ -0,0 +1,28 @@\n+var _ = require('underscore');\n+var cdb = require('cartodb.js');\n+var LayerDefinitionsCollection = require('./layer-definitions-collection');\n+\n+/**\n+ * Model that represents a visualization's Map (v3)\n+ */\n+module.exports = cdb.core.Model.extend({\n+\n+  initialize: function (attrs, opts) {\n+    if (!opts.baseUrl) throw new Error('baseUrl is required');\n+    this._baseUrl = opts.baseUrl;\n+\n+    this.layerDefinitionsCollection = new LayerDefinitionsCollection([], {\n+      // The layer definition URL is under the path of this model's API url\n+      // id might not be set from the beginning though, so the url needs to be constructed when needed\n+      baseUrl: this.url.bind(this)\n+    });\n+  },\n+\n+  url: function () {","path":"lib/assets/javascripts/cartodb3/data/map-definition-model.js","position":21,"original_position":21,"commit_id":"4944a5bcab6aeef1d1cbb5e7ceea2ad028d3197c","original_commit_id":"4944a5bcab6aeef1d1cbb5e7ceea2ad028d3197c","user":{"login":"xavijam","id":132146,"avatar_url":"https://avatars.githubusercontent.com/u/132146?v=3","gravatar_id":"","url":"https://api.github.com/users/xavijam","html_url":"https://github.com/xavijam","followers_url":"https://api.github.com/users/xavijam/followers","following_url":"https://api.github.com/users/xavijam/following{/other_user}","gists_url":"https://api.github.com/users/xavijam/gists{/gist_id}","starred_url":"https://api.github.com/users/xavijam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xavijam/subscriptions","organizations_url":"https://api.github.com/users/xavijam/orgs","repos_url":"https://api.github.com/users/xavijam/repos","events_url":"https://api.github.com/users/xavijam/events{/privacy}","received_events_url":"https://api.github.com/users/xavijam/received_events","type":"User","site_admin":false},"body":"It is likely we could replace it by ```urlRoot``` method.","created_at":"2016-02-05T10:03:11Z","updated_at":"2016-02-05T10:03:11Z","html_url":"https://github.com/CartoDB/cartodb/pull/6521#discussion_r51996640","pull_request_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6521","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/51996640"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/6521#discussion_r51996640"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6521"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6521","id":58281120,"html_url":"https://github.com/CartoDB/cartodb/pull/6521","diff_url":"https://github.com/CartoDB/cartodb/pull/6521.diff","patch_url":"https://github.com/CartoDB/cartodb/pull/6521.patch","issue_url":"https://api.github.com/repos/CartoDB/cartodb/issues/6521","number":6521,"state":"open","locked":false,"title":"Port cdb.admin.Table model (and its underlying concepts) for the new editor","user":{"login":"viddo","id":978461,"avatar_url":"https://avatars.githubusercontent.com/u/978461?v=3","gravatar_id":"","url":"https://api.github.com/users/viddo","html_url":"https://github.com/viddo","followers_url":"https://api.github.com/users/viddo/followers","following_url":"https://api.github.com/users/viddo/following{/other_user}","gists_url":"https://api.github.com/users/viddo/gists{/gist_id}","starred_url":"https://api.github.com/users/viddo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viddo/subscriptions","organizations_url":"https://api.github.com/users/viddo/orgs","repos_url":"https://api.github.com/users/viddo/repos","events_url":"https://api.github.com/users/viddo/events{/privacy}","received_events_url":"https://api.github.com/users/viddo/received_events","type":"User","site_admin":false},"body":"resolves #6516\r\n\r\nDue to a lot of legacy (e.g. missing models/collections, logic in views etc.), and strong attachment to cartodb.js v3 it was not doable to just copy-paste the old models and be done with. Instead, I migrated just enough for what we need under current requirements. This way we'll have a good base to continue from too, since some concepts were plainly missing (e.g. columns, logic is spread out in various views).\r\n\r\n```js\r\nuserModel.tablesCollection.fetch()\r\n// …\r\n\r\nt=userModel.tablesCollection.first()\r\n// to get actual table data, e.g. the schema (columns)\r\nt.fetch()\r\n// …\r\n\r\nc=t.columnsCollection.first()\r\nc.attributes // => {name: \"cartodb_id\", type: \"number\"}\r\n```\r\n\r\nI also take the opportunity to clarify how URLs should be generated following Backbone conventions/best-practices, I wrote it on the [internal doc](https://github.com/CartoDB/cartodb-management/wiki/Backbone-best-practices) (perhaps we should move that under `docs/` in this repo instead?):\r\n> - If a model belongs to a collection the URL is implicitly generated from it automatically, i.e. no need to implement any url method.\r\n- query strings should _not_ go in the url function, but in the [fetch call](http://backbonejs.org/#Collection-fetch) as `model.fetch({ data: { foo: 'bar', baz: 123 }})} // => /url?foo=bar&baz=123`. \r\n  - If you want defaults override the fetch method and set sensible defaults there.\r\n- _Exception:_ In the case that a model have some special path and/or can't follow the convention, it's correct to implement/override the url method.\r\n\r\nI have some concerns about some details, I added TODOs for those in the code, I'll comment further in the changeset so we can have threaded discussions on those topics.\r\n\r\n@xavijam can you review?\r\ncc @javisantana @alonsogarciapablo @acanimal @javierarce FYI ","created_at":"2016-02-04T12:42:16Z","updated_at":"2016-02-05T10:03:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30fa675b94e4faeba1295fa72731c9bdd17e5c32","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6521/commits","review_comments_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/6521/comments","review_comment_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/issues/6521/comments","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/4944a5bcab6aeef1d1cbb5e7ceea2ad028d3197c","head":{"label":"CartoDB:6508-sql-table-model","ref":"6508-sql-table-model","sha":"4944a5bcab6aeef1d1cbb5e7ceea2ad028d3197c","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/cartodb/deployments","created_at":"2012-07-05T15:23:45Z","updated_at":"2016-02-02T17:34:24Z","pushed_at":"2016-02-05T09:20:47Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":383083,"stargazers_count":1044,"watchers_count":1044,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":254,"mirror_url":null,"open_issues_count":792,"forks":254,"open_issues":792,"watchers":1044,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"09bbff02590d5e0c4eb6c11178cfa59c65428fb1","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/cartodb/deployments","created_at":"2012-07-05T15:23:45Z","updated_at":"2016-02-02T17:34:24Z","pushed_at":"2016-02-05T09:20:47Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":383083,"stargazers_count":1044,"watchers_count":1044,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":254,"mirror_url":null,"open_issues_count":792,"forks":254,"open_issues":792,"watchers":1044,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6521"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/6521"},"issue":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/6521"},"comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/6521/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6521/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/6521/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/cartodb/statuses/4944a5bcab6aeef1d1cbb5e7ceea2ad028d3197c"}}}}