module.exports = function(){
	this.factory = function(relativePathToModel, newObject){
		if(typeof newObject != 'object'){
			throw new Error('FactoryDude can only take objects to create new mongoose entries');
			return;
		}
		var model = require(relativePathToModel);
		var newModel = new model();
		var attrCounter = 0;
		for(var attr in newObject){
			eval('newModel.'+attr+' = newObject.'+attr);
		}
		newModel.save(function(err){
			if(err){
				throw err;
			}
		});
		return newModel
	};
	
	this.reference = function(queryArg){
		
	};
};

@@ -22,16 +22,38 @@
 tion()%7B%0A
+%09var factories = %5B%5D;%0A%0A
 %09this.fa
@@ -69,16 +69,29 @@
 unction(
+factoryName, 
 relative
@@ -381,16 +381,54 @@
 bject)%7B%0A
+%09%09%09if(hasAttribute(newModel, attr))%7B%0A%09
 %09%09%09eval(
@@ -467,16 +467,103 @@
 +attr);%0A
+%09%09%09%7D%0A%09%09%09else%7B%0A%09%09%09%09throw new Error('Attribute: '+attr+' does not exist in model');%0A%09%09%09%7D%0A
 %09%09%7D%0A%09%09ne
@@ -627,16 +627,72 @@
 %7D%0A%09%09%7D);%0A
+%09%09factories.push(%7Bname: factoryName, model: newModel%7D);%0A
 %09%09return
@@ -700,16 +700,17 @@
 newModel
+;
 %0A%09%7D;%0A%09%0A%09
@@ -739,25 +739,895 @@
 ion(
-queryArg)
+factoryName, attr)%7B%0A%09%09var matchModel = findFactory(factoryName);%0A%09%09if(hasAttribute(matchModel, attr))%7B%0A%09%09%09return eval('matchModel.'+attr);%0A%09%09%7D%0A%09%09else%7B%0A%09%09%09throw new Error('Cannot reference '+factoryName+', '+attr+' does not exist within factory');%0A%09%09%7D%0A%09%09%0A%09%7D;%0A%0A%09this.destroy = function(factoryName)%7B%0A%09%09var destroyModel = findFactory(factoryName);%0A%0A%09%7D%0A%0A%09var hasAttribute = function(model, attr)%7B%0A%09%09var result = false;%0A%09%09for(var comparison in model)%7B%0A%09%09%09result = (comparison == attr);%0A%09%09%09if(result)%7B%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return result;%0A%09%7D;%0A%0A%09var findFactory = function(factoryName)%7B%0A%09%09var match = false;%0A%09%09var matchModel = %7B%7D;%0A%09%09for (var i = 0; i %3C factories.length; i++) 
 %7B%0A%09%09
+%09
+match = (factories%5Bi%5D.name == factoryName)%0A%09%09%09if(match)%7B%0A%09%09%09%09matchModel = factories%5Bi%5D.model;%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09if(match)%7B%0A%09%09%09return matchModel;%0A%09%09%7D%0A%09%09else%7B%0A%09%09%09throw new Error('Factory does not exist');%0A%09%09%7D
 %0A%09%7D
-;
 %0A%7D;%0A

add destroy and reference