Comparing version 0.9.5 to 0.9.6
@@ -28,3 +28,3 @@ !function(){ | ||
Class.define(this, '_changedValues' , Class([]).Writable()); | ||
Class.define(this, '_mappings' , Class({})); | ||
Class.define(this, '_mappings' , Class({}).Writable()); | ||
Class.define(this, '_belongsTo' , Class({})); | ||
@@ -31,0 +31,0 @@ Class.define(this, '_references' , Class({})); |
@@ -444,3 +444,2 @@ !function(){ | ||
// create a child tree node for the querybuilder | ||
@@ -447,0 +446,0 @@ resource = new this._queryBuilders[targetModelName].Resource({ |
@@ -140,3 +140,3 @@ !function(){ | ||
if (parentRecords && parentRecords.length) { | ||
parentRecords.forEach(function(parentRecord){ | ||
parentRecords.forEach(function(parentRecord) { | ||
//log(childResource.loaderId); | ||
@@ -143,0 +143,0 @@ if (childResource.type === 'mapping') { |
@@ -96,3 +96,3 @@ !function(){ | ||
else { | ||
this._getChangedRecords(function(err, added, removed){ | ||
this._getChangedRecords(function(err, added, removed) { | ||
if (err) callback(err); | ||
@@ -196,2 +196,3 @@ else { | ||
if (this.isMapping) { | ||
// mapping, notexplicitly selected | ||
var values = {}; | ||
@@ -214,2 +215,15 @@ | ||
} | ||
else if (this._definition.model.isMapping) { | ||
// mapping, explicitly selected | ||
var values = {}; | ||
// get mapping columns | ||
this._definition.model.mappingColumns.forEach(function(columnName) { | ||
values[columnName] = record[columnName]; | ||
}.bind(this)); | ||
// records were removed before | ||
if (debug) log.info('Relatingset for «'+this._definition.name+'» is deleting a relation record ...'); | ||
transaction[this._definition.model.name](values).limit(1).delete(next) | ||
} | ||
else next(); | ||
@@ -216,0 +230,0 @@ }.bind(this), callback); |
@@ -110,3 +110,2 @@ !function () { | ||
// make sure we have access to the orm (circular dependency) | ||
@@ -119,3 +118,3 @@ if (!ORM) ORM = require('./ORM'); | ||
if (debug) log.info('New resource ['+(this.id||this._id)+'] '+this.name.cyan+', has rootFilters: '+ ((!!this.hasRootFilter)+'').yellow+', is selected: '+ ((!!this.selected)+'').yellow+''); | ||
if (debug) log.info('New resource ['+(this.id||this._id)+'] '+this.name.cyan+', has rootFilters: '+ ((!!this._hasRootFilters)+'').yellow+', is selected: '+ ((!!this.selected)+'').yellow+''); | ||
} | ||
@@ -122,0 +121,0 @@ |
{ | ||
"name" : "ee-orm" | ||
, "description" : "ORM for postgres and mysql. Loads and saves referenced entites, executes complex queries, supports joins, transactions, complex database clusters, connection pooling and much more. No conventions." | ||
, "version" : "0.9.5" | ||
, "version" : "0.9.6" | ||
, "homepage" : "https://github.com/eventEmitter/ee-orm" | ||
@@ -6,0 +6,0 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" |
39
test.js
@@ -22,9 +22,40 @@ | ||
new db.image({ | ||
url: 'mapping deletion test' | ||
, event: db.event({id:2}) | ||
}).save().then(function() { | ||
return db.event({id:2}, ['*']).getEvent_image('*').fetchImage(['*']).findOne(); | ||
}).then(function(evt) { | ||
log(evt); | ||
return evt.event_image[0].delete(); | ||
}).then(function() { | ||
return db.event({id:2}, ['*']).getEvent_image('*').fetchImage(['*']).findOne(); | ||
}).then(function(evt) { | ||
log(evt); | ||
}).catch(log); | ||
/* | ||
db.shop(['*'], {id: 1}) | ||
.getSale({id: 23}, '*') | ||
.fetchSale_variant(['*']) | ||
.find() | ||
.then(function(data) { | ||
log.highlight('round #1, data', data); | ||
//throw new Error('thats it'); | ||
db.event(['*', ORM.count('id', 'idCount')]) | ||
.joinVenue() | ||
.group('id') | ||
.find(log); | ||
data[0].sale[23].sale_variant.splice(0, 1); | ||
return data[0].sale[23].save(); | ||
}).then(function(){ | ||
log.highlight('round #2'); | ||
return db.shop(['*'], {id:1}) | ||
.fetchAccount(['*']) | ||
.getSale(['*'], {id:23}) | ||
.fetchSale_variant(['*']).find(); | ||
}).then(function(data){ | ||
log.highlight('round #3'); | ||
log(data); | ||
}).catch(log) | ||
*/ | ||
}); |
@@ -720,3 +720,3 @@ | ||
describe('[Deleting]', function(){ | ||
it('A model should be deleted when the delete method is called on it', function(done){ | ||
it('A model should be deleted when the delete method is called on it', function(done) { | ||
db.event({id:1}).findOne(function(err, evt){ | ||
@@ -739,3 +739,4 @@ if (err) done(err); | ||
it('should remove items from a related set when they are delted', function(done){ | ||
it('should remove items from a related set when they are delted', function(done) { | ||
db.event({id:2}, ['*']).fetchImage(['*']).findOne(function(err, evt){ | ||
@@ -754,2 +755,20 @@ if (err) done(err); | ||
}); | ||
it('should remove items from a related set which was explicitly loaded and items were removed', function(done) { | ||
new db.image({ | ||
url: 'mapping deletion test' | ||
, event: db.event({id:2}) | ||
}).save().then(function() { | ||
return db.event({id:2}, ['*']).getEvent_image('*').fetchImage(['*']).findOne(); | ||
}).then(function(evt) { | ||
assert.equal(JSON.stringify(evt), '{"event_image":[{"id_event":2,"image":{"id":8,"url":"mapping deletion test"},"id_image":8}],"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}'); | ||
return evt.event_image[0].delete(); | ||
}).then(function() { | ||
return db.event({id:2}, ['*']).getEvent_image('*').fetchImage(['*']).findOne(); | ||
}).then(function(evt) { | ||
assert.equal(JSON.stringify(evt), '{"id":2,"id_venue":2,"title":"Mapping Test","startdate":"1970-01-01T00:00:00.000Z","enddate":null,"canceled":null,"created":null,"updated":null,"deleted":null}'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
}); | ||
@@ -756,0 +775,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
290682
5545