From cb9f0c3d16e0f7fe7c75665e7021d3cf9577a7d5 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Sat, 10 Nov 2012 09:28:07 +0400 Subject: [PATCH] Better docs, no warning --- README.md | 14 +++++++++++++- lib/railway.js | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81a01d8a..f679ac4a 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,9 @@ var Post = schema.define('Post', { title: { type: String, length: 255 }, content: { type: Schema.Text }, date: { type: Date, default: Date.now }, - published: { type: Boolean, default: false } + published: { type: Boolean, default: false, index: true } }); + // simplier way to describe model var User = schema.define('User', { name: String, @@ -36,6 +37,15 @@ var User = schema.define('User', { age: Number }); +// define any custom method +User.prototype.getNameAndAge = function () { + return this.name + ', ' + this.age; +}; + +// models also accessible in schema: +schema.models.User; +schema.models.Post; + // setup relationships User.hasMany(Post, {as: 'posts', foreignKey: 'userId'}); // creates instance methods: @@ -74,6 +84,8 @@ Post.all(cb) Post.all({where: {userId: user.id}, order: 'id', limit: 10, skip: 20}); // the same as prev user.posts(cb) +// get one latest post +Post.findOne({where: {published: true}, order: 'date DESC'}, cb); // same as new Post({userId: user.id}); user.posts.build // save as Post.create({userId: user.id}, cb); diff --git a/lib/railway.js b/lib/railway.js index 98e2a1c0..44d5e7a4 100644 --- a/lib/railway.js +++ b/lib/railway.js @@ -90,7 +90,7 @@ Object.keys(models).forEach(function (model) { if (displayWarning) { var $ = railway.utils.stylize.$; - require('util').puts($('WARNING:').bold.red + ' ' + $('I can see that you\'ve added validation to db/schema.js. However schema.js file is only used to describe database schema. Therefore validations configured in db/schema.js will be ignored.\nFor business logic (incl. validations) please create models as separate .js files here: app/models/*.js').yellow); + // require('util').puts($('WARNING:').bold.red + ' ' + $('I can see that you\'ve added validation to db/schema.js. However schema.js file is only used to describe database schema. Therefore validations configured in db/schema.js will be ignored.\nFor business logic (incl. validations) please create models as separate .js files here: app/models/*.js').yellow); } function log(str, startTime) {