Skip to content

Commit

Permalink
models should export both schema and model to use the schema across f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
henrikhaugboelle committed Jun 1, 2012
1 parent 42a7159 commit 7b035f7
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 34 deletions.
8 changes: 1 addition & 7 deletions example/server/app.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
var rest = require('./rest'),
Controller = require('./app/controller');
var rest = require('../../lib/rest');

rest.configure(function(rest) {
rest.auth.secret = 'cat';

rest.mongoose.host = 'localhost';
rest.mongoose.port = 27017;
rest.mongoose.db = 'db';

rest.paths.controllers = __dirname + '/controllers/';
rest.paths.models = __dirname + '/models/';

rest.controller = Controller;
});


rest.listen(5000);


12 changes: 0 additions & 12 deletions example/server/controllers/blog.js

This file was deleted.

2 changes: 1 addition & 1 deletion example/server/controllers/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var _ = require('underscore'),
Controller = require('../app/controller');
Controller = require('../../../lib/controller');

var UserController = function() {
this._ctor.apply(this, arguments);
Expand Down
10 changes: 0 additions & 10 deletions example/server/models/blog.js

This file was deleted.

7 changes: 5 additions & 2 deletions example/server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = mongoose.ObjectId;

module.exports = mongoose.model('User', new Schema({
var schema = new Schema({
firstname: String,
lastname: String
}, {
strict: true
}));
});

module.exports.Schema = schema;
module.exports.Model = mongoose.model('User', schema);
2 changes: 1 addition & 1 deletion lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Controller.prototype = {
} else {
path.exists(self.paths.models + url + '.js', function(exists) {
if (exists) {
self._models[url] = require(self.paths.models + url);
self._models[url] = require(self.paths.models + url).Model;
callback.call(context, null, self._models[url]);
} else {
self._models[url] = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Rest.prototype.listen = function() {

this._app.listen.apply(this._app, arguments);

console.log("Rest is listening on port %d", Array.prototype.slice.call(arguments));
console.log("rest is listening on port %d", Array.prototype.slice.call(arguments));
};

module.exports = new Rest();

0 comments on commit 7b035f7

Please sign in to comment.