Skip to content

Instantly share code, notes, and snippets.

@dreamr
Created February 22, 2012 00:53
Show Gist options
  • Save dreamr/1880284 to your computer and use it in GitHub Desktop.
Save dreamr/1880284 to your computer and use it in GitHub Desktop.
Why is it that I end up with the ObjectId instead of unit.race -> Race() ?
<div class="clearfix">
<%- form.label("race") %>
<div class="input">
<%- form.input( 'race' ) %>
</div>
</div>
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = Schema.ObjectId;
var Race = describe('Race', function () {
property('name', String);
});
var Unit = describe('Unit', function () {
property('name', String);
property('race', { type: ObjectId, ref: 'Race'});
property('type', String);
property('at1', Number);
property('at2', Number);
property('at3', Number);
property('dt1', Number);
property('dt2', Number);
property('dt3', Number);
});
Unit.attackTypes = function () {
return ['at1', 'at2', 'at3'];
};
Unit.defenseTypes = function () {
return ['dt1', 'dt2', 'dt3'];
};
Unit.types = function () {
return ['land', 'water', 'air', 'space'];
};
// Unit.races = function () {
// return ['terran', 'alien'];
// };
Unit.validatesPresenceOf('name')
Unit.validatesLengthOf('name', {min: 5})
Unit.validatesPresenceOf('at1')
Unit.validatesPresenceOf('at2')
Unit.validatesPresenceOf('at3')
Unit.validatesPresenceOf('dt1')
Unit.validatesPresenceOf('dt2')
Unit.validatesPresenceOf('dt3')
Unit.validatesPresenceOf('raceId')
Unit.validatesPresenceOf('type')
Unit.validatesInclusionOf('type', {in: Unit.types()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment