These are chat archives for edbirmingham/network

29th
Oct 2015
saabdoli
@saabdoli
Oct 29 2015 00:34
@anthonycrumley I've tried implementing the discriminator but i keep getting an error telling me that no schema has been registered for Participant.
Anthony Crumley
@anthonycrumley
Oct 29 2015 01:32
@saabdoli Did you try this at the top of the member model file in the Module dependencies, Member = mongoose.model('Member').
But with Participatn
Participant = mongoose.model('Participant')
saabdoli
@saabdoli
Oct 29 2015 01:36
Yes, here is the top of my file
var mongoose = require('mongoose'),
    errorHandler = require('./errors.server.controller'),
    Participant = mongoose.model('Participant'),
    _ = require('lodash');
Anthony Crumley
@anthonycrumley
Oct 29 2015 01:41
What does the part with the discriminator look like?
saabdoli
@saabdoli
Oct 29 2015 01:44
var MemberSchema = Participant.discriminator('Member', 
    new Schema({ 
    address: {             
        type: String,
        default: '',
    },
    identity: {
        type: String,
        trim: true,
        default: '',
        required: 'Please choose an option for "Who are you ?"'
    },
    shirtSize: {
        type: String,
        required: 'Please choose a shirt size'
    },
    talent: {
        type: String,
        required: 'Please provide a talent/passion.'
    },
    affiliation: {
        type: String,
        trim: true,
        default: '',
        required: 'Please fill in the affiliation'
    },
    placeOfWorship: {
        type: String,
        trim: true,
        default: '',
    },
    communityNetworks: [String],
    extraGroups: [String],
    ortherNetworks: [String],

    }));
Anthony Crumley
@anthonycrumley
Oct 29 2015 01:50
Please put the whole contents of the member model and the error message.
With the stack trace.
I don't see Schema = mongoose.Schema; in the Module dependencies shown above.
saabdoli
@saabdoli
Oct 29 2015 01:58
Member model:
'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    Schema = mongoose.Schema,                    
    Participant = mongoose.model('Participant'),
    _ = require('lodash');

/**
 * Member Schema
 */
var MemberSchema = Participant.discriminator('Member', 
    new Schema({ 
            address: {             // Should address be composed of subdocuments?
        type: String,
        default: '',
    },
    identity: {
        type: String,
        trim: true,
        default: '',
        required: 'Please choose an option for "Who are you ?"'
    },
    shirtSize: {
        type: String,
        required: 'Please choose a shirt size'
    },
    talent: {
        type: String,
        required: 'Please provide a talent/passion.'
    },
    affiliation: {
        type: String,
        trim: true,
        default: '',
        required: 'Please fill in the affiliation'
    },
    placeOfWorship: {
        type: String,
        trim: true,
        default: '',
    },
    communityNetworks: [String],
    extraGroups: [String],
    ortherNetworks: [String],

    }));


mongoose.model('Member', MemberSchema);
Error:
saabdoli:~/workspace (member-admin) $ grunt
Running "jshint:all" (jshint) task
>> 101 files lint free.

Running "csslint:all" (csslint) task
>> 2 files lint free.
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /home/ubuntu/workspace/config/express.js:32:3
    at Array.forEach (native)
    at module.exports (/home/ubuntu/workspace/config/express.js:31:49)
    at Object.<anonymous> (/home/ubuntu/workspace/server.js:24:38)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
[nodemon] app crashed - waiting for file changes before starting...
Running "jshint:all" (jshint) task
>> 101 files lint free.

Running "csslint:all" (csslint) task
>> 2 files lint free.

Running "concurrent:default" (concurrent) task
Running "nodemon:dev" (nodemon) task
[nodemon] v1.3.8
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: app/views/**/*.* gruntfile.js server.js config/**/*.js app/**/*.js
[nodemon] starting `node --debug server.js`
debugger listening on port 5858
Running "watch" task
Waiting...
NODE_ENV is not defined! Using default development environment

/home/ubuntu/workspace/node_modules/mongoose/lib/index.js:323
      throw new mongoose.Error.MissingSchemaError(name);
            ^
MissingSchemaError: Schema hasn't been registered for model "Participant".
Use mongoose.model(name, schema)
    at Mongoose.model (/home/ubuntu/workspace/node_modules/mongoose/lib/index.js:323:13)
    at Object.<anonymous> (/home/ubuntu/workspace/app/models/member.server.model.js:8:25)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /home/ubuntu/workspace/config/express.js:32:3
    at Array.forEach (native)
    at module.exports (/home/ubuntu/workspace/config/express.js:31:49)
    at Object.<anonymous> (/home/ubuntu/workspace/server.js:24:38)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
[nodemon] app crashed - waiting for file changes before starting...
Anthony Crumley
@anthonycrumley
Oct 29 2015 03:35
@saabdoli This is kinda crazy but it looks like the files are loading in alphabetical order and since it is interpreted instead of compiled, the Participant model is not loaded when the Member model tries to load.
Add this to your module dependencies... participant = require('./participant.server.model'), right before Participant = mongoose.model('Participant'),
This forces it to load the Participant model before the Member model.
This works as long as you don't have circular dependencies.
@saabdoli ^^
saabdoli
@saabdoli
Oct 29 2015 04:36
great
@anthonycrumley that fixed it
saabdoli
@saabdoli
Oct 29 2015 05:24
@anthonycrumley How do you go about testing your models. For instance, I have this Member model. Should I just try to enter some Members into the database through the shell?
Anthony Crumley
@anthonycrumley
Oct 29 2015 12:39
@saabdoli At the command line go into the node repl, load the server, load the dependencies, play with the code.

From the console prompt...

node

From the node prompt load the code...

var s = require('./server.js');
var mongoose = require('mongoose'),
    Member = mongoose.model('Member'),
    _ = require('lodash');

Now test out the Member model.

There is also the app/tests folder with model tests.