Merge branch 'release/1.2.3' into production

This commit is contained in:
Raymond Feng 2013-11-19 11:02:15 -08:00
commit ed8aa854c5
6 changed files with 22 additions and 20 deletions

View File

@ -30,11 +30,16 @@ Customer.hasMany(Order, {as: 'orders', foreignKey: 'customerId'});
Customer.create({name: 'Ray'}, function (err, customer) {
Order.create({customerId: customer.id, orderDate: new Date()}, function (err, order) {
customer.orders(console.log);
customer.orders.create({orderDate: new Date()}, console.log);
customer.orders.create({orderDate: new Date()}, function(err, order) {
console.log(order);
Customer.include([customer], 'orders', function(err, results) {
console.log('Results: ', results);
});
customer.orders.findById('2', console.log);
customer.orders.destroy('2', console.log);
});
});
});
var Physician = ds.createModel('Physician', {

View File

@ -548,26 +548,23 @@ DataSource.prototype.getModelDefinition = function(name) {
DataSource.prototype.attach = function (modelClass) {
if(modelClass.dataSource === this) {
// Already attached to the data source
return;
return modelClass;
}
if(modelClass.modelBuilder !== this.modelBuilder) {
this.modelBuilder.definitions[modelClass.modelName] = modelClass.definition;
this.modelBuilder.models[modelClass.modelName] = modelClass;
// reset the modelBuilder
modelClass.modelBuilder = this.modelBuilder;
}
var className = modelClass.modelName;
var modelDef = modelClass.modelBuilder.getModelDefinition(className);
var properties = modelDef.properties;
var settings = modelDef.settings;
// redefine the dataSource
modelClass.dataSource = this;
// add to def
var def = new ModelDefinition(this.modelBuilder, className, properties, settings);
def.build();
this.modelBuilder.definitions[className] = def;
this.modelBuilder.models[className] = modelClass;
this.setupDataAccess(modelClass, settings);
this.setupDataAccess(modelClass, modelClass.settings);
modelClass.emit('dataSourceAttached', modelClass);
return modelClass;
return this;
};
/**

View File

@ -119,7 +119,7 @@ Inclusion.include = function (objects, include, cb) {
req['include'] = subInclude;
return function(cb) {
relation.modelTo.all(req, function(err, objsIncluded) {
relation.modelTo.find(req, function(err, objsIncluded) {
for (var i = 0; i < objsIncluded.length; i++) {
delete keysToBeProcessed[objsIncluded[i][relation.keyTo]];
var objectsFrom = objsByKeys[relation.keyFrom][objsIncluded[i][relation.keyTo]];

View File

@ -55,7 +55,7 @@ Relation.hasMany = function hasMany(anotherClass, params) {
};
// each instance of this class should have method named
// pluralize(anotherClass.modelName)
// which is actually just anotherClass.all({where: {thisModelNameId: this[idName]}}, cb);
// which is actually just anotherClass.find({where: {thisModelNameId: this[idName]}}, cb);
var scopeMethods = {
findById: find,
destroy: destroy

View File

@ -139,7 +139,7 @@ function defineScope(cls, targetClass, name, params, methods) {
- If fetching the Elements on which destroyAll is called results in an error
*/
function destroyAll(cb) {
targetClass.all(this._scope, function (err, data) {
targetClass.find(this._scope, function (err, data) {
if (err) {
cb(err);
} else {

View File

@ -1,6 +1,6 @@
{
"name": "loopback-datasource-juggler",
"version": "1.2.2",
"version": "1.2.3",
"description": "LoopBack DataSoure Juggler",
"keywords": [
"StrongLoop",