Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better docs, no warning

  • Loading branch information...
commit cb9f0c3d16e0f7fe7c75665e7021d3cf9577a7d5 1 parent c28b803
@1602 authored
Showing with 14 additions and 2 deletions.
  1. +13 −1 README.md
  2. +1 −1  lib/railway.js
View
14 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);
View
2  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) {
Please sign in to comment.
Something went wrong with that request. Please try again.