Created
December 16, 2014 17:15
-
-
Save JemiloII/89ab93f65ea0c481be4a to your computer and use it in GitHub Desktop.
Is this possible to do in sails? Reference a model from another model.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Bar.js | |
* | |
* @description :: Model for the Bar Collection | |
* @docs :: http://sailsjs.org/#!documentation/models | |
*/ | |
module.exports = { | |
attributes: { | |
name: 'string' | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Foo.js | |
* | |
* @description :: Model for the Foo Collection | |
* @docs :: http://sailsjs.org/#!documentation/models | |
*/ | |
module.exports = { | |
attributes: { | |
baz: function(params){ | |
bar.findOrCreate(params).exec(function(err, data){ | |
if(err){ return err; } | |
return data; | |
}); | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* FooController | |
* | |
* @description :: Server-side logic for managing foos | |
* @help :: See http://links.sailsjs.org/docs/controllers | |
*/ | |
module.exports = { | |
create: function(req, res){ | |
// baz is an object | |
Foo.create({baz: req.body.baz}).exec(function(err, data){ | |
if(err){ return res.serverError(err); } | |
return res.json(data); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment