{"action":"created","issue":{"url":"https://api.github.com/repos/balderdashy/sails/issues/3783","repository_url":"https://api.github.com/repos/balderdashy/sails","labels_url":"https://api.github.com/repos/balderdashy/sails/issues/3783/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/sails/issues/3783/comments","events_url":"https://api.github.com/repos/balderdashy/sails/issues/3783/events","html_url":"https://github.com/balderdashy/sails/issues/3783","id":164486980,"number":3783,"title":"Create a sails model using the controller","user":{"login":"edohkodjo","id":13002951,"avatar_url":"https://avatars.githubusercontent.com/u/13002951?v=3","gravatar_id":"","url":"https://api.github.com/users/edohkodjo","html_url":"https://github.com/edohkodjo","followers_url":"https://api.github.com/users/edohkodjo/followers","following_url":"https://api.github.com/users/edohkodjo/following{/other_user}","gists_url":"https://api.github.com/users/edohkodjo/gists{/gist_id}","starred_url":"https://api.github.com/users/edohkodjo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edohkodjo/subscriptions","organizations_url":"https://api.github.com/users/edohkodjo/orgs","repos_url":"https://api.github.com/users/edohkodjo/repos","events_url":"https://api.github.com/users/edohkodjo/events{/privacy}","received_events_url":"https://api.github.com/users/edohkodjo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-07-08T08:55:31Z","updated_at":"2016-09-05T11:43:46Z","closed_at":null,"body":"<!--\r\n======================================================\r\nHELLO, and welcome to the (experimental) Sailsbot\r\nissue-submission system.  If you encounter any\r\nproblems with this system, please contact\r\nsgress454@treeline.io\r\n\r\nFIRST THINGS FIRST: before posting, please carefully \r\nread the contribution guide (http://bit.ly/sails-issue-guide), \r\nparticularly if this is a security issue or an issue of a \r\nnon-technical nature (Github org issues, code of conduct\r\nissues, etc.).  Those should be sent directly to inquiries@treeline.io.\r\n\r\nNOW THEN: please fill out the following info \r\n(Don't change text between **) \r\n======================================================\r\n### BEGIN VERSION INFO ###\r\n-->\r\n\r\n**Sails version**: 0.12.3\r\n**Node version**: 0.10.42\r\n**NPM version**: 3.10.2\r\n**Operating system**: fc23.x86_64\r\n\r\n<!-- \r\n### END VERSION INFO ###\r\n======================================================\r\nGREAT! - Now read carefully \r\n(Sailsbot will know if you don't)!  \r\n======================================================\r\n\r\nBefore you submit an issue for Sails, please make sure you have read the issue contribution guide (http://bit.ly/sails-issue-guide) carefully, and then verify the following by typing an X in between each set of [ ] brackets below (don't make any other changes to the text!):\r\n\r\n### BEGIN PLEDGE ###\r\n- [X] I am experiencing a concrete technical issue (aka a bug) with Sails (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request).  If you're not 100% certain whether it's a bug or not, that's okay--you may continue.  The worst that can happen is that the issue will be closed and we'll point you in the right direction.\r\n\r\n- [X] I am not asking a question about how to use Sails or about whether or not Sails has a certain feature (please refer to the documentation(http://sailsjs.org), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails).\r\n\r\n- [X] I have already searched for related issues, and found none open (if you found a related _closed_ issue, please link to it in your post).\r\n\r\n- [X] My issue title is concise, on-topic and polite (\"jst.js being removed from layout.ejs on lift\" is good; \"templates dont work\" or \"why is sails dumb\" are not so good).\r\n\r\n- [X] I have tried all the following (if relevant) and my issue remains:\r\n  - Make sure you have the right app lifted.\r\n  - Make sure you've killed the Sails server with CTRL+C and started it again.\r\n  - Make sure you closed any open browser tabs pointed at localhost before starting Sails.\r\n  - Make sure you do not have any other Sails apps running in other terminal windows.\r\n  - Make sure the app you are using to reproduce the issue has a clean node_modules/ directory, meaning:\r\n    * no dependencies are linked (e.g. you haven't run npm link foo)\r\n    * that you haven't made any inline changes to files in the node_modules/ folder\r\n    * that you don't have any weird global dependency loops. The easiest way to double-check any of the above, if you aren't sure, is to run: rm -rf node_modules && npm cache clear && npm install.\r\n\r\nand finally...\r\n- [X] **I can provide steps to reproduce this issue that others can follow.**\r\n\r\nIdeally, this involves creating a new repo that demonstrates the problem (see instructions at http://bit.ly/sails-issue-repro).  Even though your issue may seem so simple to reproduce that a new repo is unnecessary, you'd be surprised how many solutions present themselves when you start from `sails new` and attempt to recreate your issue from scratch in a new app.  This ensures that the real issue isn't in your user code (a forgotten policy file, perhaps?) or in a third-party module.  If you're absolutely _convinced_ that a new repo is unnecessary, provide clear, concise and _specific_ steps to reproduce the problem in your post (not \"create a model then do blueprint create\").\r\n### END PLEDGE ###\r\n\r\nOKAY--THANKS FOR READING!  Continue posting details of your issue below. -->\r\n<hr/>\r\n\r\nI am trying to create a new sails model from one of my controller. But until now I haven't find the way to achieve what I would like to do (in fact I want to create the model User). This is my code:\r\n\r\n    var Waterline = require('waterline');\r\n    var Schema = require('waterline-schema');\r\n    var CollectionLoader = require('waterline/lib/waterline/collection/loader');\r\n    creerModel: function(){\r\n      var orm = new Waterline();\r\n      var config = {\r\n        // Setup Adapters\r\n        // Creates named adapters that have have been required\r\n        adapters: {\r\n            'default': 'sails-disk',\r\n            'sails-disk': require('sails-disk')\r\n        },\r\n\r\n        // Build Connections Config\r\n        // Setup connections using the named adapter configs\r\n        connections: {\r\n            'default': {\r\n                adapter: 'sails-disk'\r\n            }\r\n        }\r\n    };\r\n\r\n    orm.initialize(config, function(err, data) {\r\n        if (err) {\r\n            throw err;\r\n        }\r\n\r\n        // ORM initialized, let's add another model dynamically\r\n        var User = Waterline.Collection.extend({\r\n           identity: 'user',\r\n            connection: 'default',\r\n\r\n            attributes: {\r\n                first_name: 'string',\r\n                last_name: 'string'\r\n            }\r\n        });\r\n\r\nBut i have this error message:\r\n\r\n    var schemaAttributes = this.waterline.schema[this.identity].attributes;\r\n                                                         ^\r\n    TypeError: Cannot read property 'attributes' of undefined\r\n\r\nHow can I create the new model User using the controller? Thank you in advance!"},"comment":{"url":"https://api.github.com/repos/balderdashy/sails/issues/comments/244727397","html_url":"https://github.com/balderdashy/sails/issues/3783#issuecomment-244727397","issue_url":"https://api.github.com/repos/balderdashy/sails/issues/3783","id":244727397,"user":{"login":"HaiderMalik12","id":16774378,"avatar_url":"https://avatars.githubusercontent.com/u/16774378?v=3","gravatar_id":"","url":"https://api.github.com/users/HaiderMalik12","html_url":"https://github.com/HaiderMalik12","followers_url":"https://api.github.com/users/HaiderMalik12/followers","following_url":"https://api.github.com/users/HaiderMalik12/following{/other_user}","gists_url":"https://api.github.com/users/HaiderMalik12/gists{/gist_id}","starred_url":"https://api.github.com/users/HaiderMalik12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HaiderMalik12/subscriptions","organizations_url":"https://api.github.com/users/HaiderMalik12/orgs","repos_url":"https://api.github.com/users/HaiderMalik12/repos","events_url":"https://api.github.com/users/HaiderMalik12/events{/privacy}","received_events_url":"https://api.github.com/users/HaiderMalik12/received_events","type":"User","site_admin":false},"created_at":"2016-09-05T11:43:46Z","updated_at":"2016-09-05T11:43:46Z","body":"@mikermcneil  Model create/update is not working.\r\n\r\nSails version:0.11.0\r\nNode version:5.1.1\r\nNPM version:2.14.5\r\nOperating system:Windows 10 64-bit\r\n\r\nError: When I try to create a new companyProduct. I am getting this error.\r\n{\r\n\"error\": \"E_VALIDATION\",\r\n\"status\": 400,\r\n\"summary\": \"2 attributes are invalid\",\r\n\"model\": \"CompanyProduct\",\r\n\"invalidAttributes\": {\r\n\"quantity\": [\r\n{\r\n\"rule\": \"integer\",\r\n\"message\": \"undefined should be a integer (instead of \\\"10\\\", which is a number)\"\r\n}\r\n],\r\n\"cost_per_unit\": [\r\n{\r\n\"rule\": \"integer\",\r\n\"message\": \"undefined should be a integer (instead of \\\"100\\\", which is a number)\"\r\n}\r\n]\r\n}\r\n}\r\n\r\nModels:\r\n/**\r\n\r\nCompanyProduct.js */\r\nmodule.exports = {\r\ntableName: 'company_products',\r\nsortValues: ['companies', 'products'],\r\n\r\nattributes: {\r\n'quantity': {\r\n'type': 'integer',\r\nsize: 6\r\n},\r\n'cost_per_unit': {\r\n'type': 'integer'\r\n},\r\n\r\n// Associations\r\n'product': {\r\n    'columnName': 'product_id',\r\n    'model': 'product',\r\n    'required': true\r\n},\r\n'company': {\r\n    'columnName': 'company_id',\r\n    'model': 'company',\r\n    'required': true\r\n}\r\n},\r\n\r\ngetSortValues: function() {\r\nreturn this.sortValues;\r\n}\r\n};\r\n\r\n/**\r\n\r\nProduct.js *\r\n@description :: Our entire application products available for clients to purchase or added to orders\r\n@docs :: http://sailsjs.org/#!documentation/models */\r\nmodule.exports = {\r\ntableName: 'products',\r\nsortValues: ['id', 'title', 'product_type', 'access_key'],\r\n\r\nattributes: {\r\n'title': {\r\n'type': 'string',\r\n'required': true\r\n},\r\n'description': {\r\n'type': 'text',\r\n'defaultsTo': ''\r\n},\r\n'cost_ex_vat': {\r\n'type': 'integer',\r\nrequired: true\r\n},\r\n'is_private': {\r\n'type': 'boolean',\r\n'defaultsTo': false\r\n},\r\nquantity: {\r\ntype: 'integer',\r\nmaxSize: 4\r\n},\r\naccess_key: {\r\ntype: 'string',\r\nsize: 40,\r\nrequired: true,\r\nunique: true\r\n},\r\n\r\n// Associations\r\n'company_product': {\r\n'collection': 'companyproduct',\r\n'via': 'product'\r\n},\r\n'packages': {\r\n'collection': 'productpackages',\r\n'via': 'product'\r\n},\r\n'product_type': {\r\n'columnName': 'product_type_id',\r\n'model': 'ProductType'\r\n},\r\n'transaction_products': {\r\n'collection': 'transactionproduct',\r\n'via': 'product'\r\n}\r\n},\r\n\r\ngetSortValues: function () {\r\nreturn this.sortValues;\r\n}\r\n};"}}
{"actor":{"display_login":"HaiderMalik12"}}