Mongoose plugin for simple addons like findOrCreate
npm install supergoosesupergoose 
==================
Mongoose simple plugin adding some
handy functions.
* parentOf/oneToMany
* childOf/manyToOne
* hasA/oneToOne
* hasMany/manyToMany
* Relationship
Installation
------------
npm install supergoose
Usage
-----
``javascript`
var supergoose = require('supergoose')
var ClickSchema = new Schema({ ... });
ClickSchema.plugin(supergoose, [options]);
var Click = mongoose.model('Click', ClickSchema)
__Arguments__
* supergoose
__Valid Options__
* instance
* messages
---------------------------------------
Adds find or create functionality to mongoose models. This is handy
for libraries like passport.js which require it
`javascript`
Click.findOrCreate({ip: '127.0.0.1'}, function(err, doc) {});
Click.findOrCreate({ip: '127.0.0.1'}, {browser: 'Chrome'}, function(err, click) {})
__Arguments__
* query
* [doc]
* [options]
* callback
__Valid Options__
* upsert
---------------------------------------
Parses the complex validation errors return from mongoose into a simple
array of messages to be displayed as flash messages or something similar
`javascript`
var supergoose = require('supergoose')
var ClickSchema = new Schema({ip: {type: String, required: true}});
Click.plugin(supergoose, {messages: {'required': '%s is a required field'}});
var Click = mongoose.model('Click', ClickSchema);
The Click model now has an errors static method
`javascript`
Click.create({}, function(err, click) {
if(err) {
Click.errors(err, function(messages) {
console.log(messages);
// outputs ['ip is a required field']
})
}
});
__Arguments__
* errors
* callback
---------------------------------------
* parentOf / oneToMany - Creates a one to many relationship
* childOf / manyToOne - Creates a many to one relationship
* hasA / oneToOne - Creates a one to one relationship
* hasMany / manyToMany - Creates a many to many relationship
__Arguments__
* modelName
* [myPath]
__Returns__
* Relationship
---------------------------------------
When a relationship is created, it adds a path that refers to the related model on the schema that creates it.
The relationship object has one property:
#### enforceWith
`javascript
var supergoose = require('supergoose')
var mongoose = require('mongoose')
var ClickSchema = new Schema({ip: {type: String, required: true}, _user: {type: ObjectId}});
var UserSchema = new Schema({name: String})
UserSchema.plugin(supergoose, {instance: mongoose});
UserSchema.parentOf('Click', 'clickCollection').enforceWith('_user')
``
__Arguments__
* itsPath
* [options]
__Valid Options__
* delete
License
-------
MIT License