Skip to content

Commit

Permalink
Release 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Gama committed Jun 14, 2016
1 parent a3e4570 commit 93030cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# Changelog

## [1.0.2](https://github.com/seegno/bookshelf-cascade-delete/tree/1.0.2)
## [1.0.3](https://github.com/seegno/bookshelf-cascade-delete/tree/1.0.3)

[Full Changelog](https://github.com/seegno/bookshelf-cascade-delete/compare/1.0.2...1.0.3)

**Closed issues:**

- many to many, junction table. [\#13](https://github.com/seegno/bookshelf-cascade-delete/issues/13)

**Merged pull requests:**

- Fix destroying models with many-to-many relations [\#15](https://github.com/seegno/bookshelf-cascade-delete/pull/15) ([ricardogama](https://github.com/ricardogama))

## [1.0.2](https://github.com/seegno/bookshelf-cascade-delete/tree/1.0.2) (2016-05-22)
[Full Changelog](https://github.com/seegno/bookshelf-cascade-delete/compare/1.0.1...1.0.2)

**Closed issues:**
Expand Down
18 changes: 11 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ exports.default = function (Bookshelf) {
dependencyMap: function dependencyMap() {
var _this3 = this;

if (!this.dependents) {
var skipDependents = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];

if (skipDependents || !this.dependents) {
return;
}

Expand All @@ -76,11 +78,14 @@ exports.default = function (Bookshelf) {

var relatedData = _prototype$dependent.relatedData;

var skipDependents = relatedData.type === 'belongsToMany';

return (0, _extends4.default)({}, result, (0, _defineProperty3.default)({}, dependent, {
dependents: relatedData.target.dependencyMap(),
dependents: relatedData.target.dependencyMap(skipDependents),
key: relatedData.key('foreignKey'),
model: relatedData.target
model: relatedData.target,
skipDependents: skipDependents,
tableName: skipDependents ? relatedData.joinTable() : relatedData.target.prototype.tableName
}));
}, {});
},
Expand All @@ -90,17 +95,16 @@ exports.default = function (Bookshelf) {

// Build delete queries for each dependent.
var queries = (0, _lodash.reduce)(this.dependencyMap(), function (result, _ref) {
var tableName = _ref.tableName;
var key = _ref.key;
var model = _ref.model;
var _model$prototype = model.prototype;
var idAttribute = _model$prototype.idAttribute;
var tableName = _model$prototype.tableName;
var skipDependents = _ref.skipDependents;

var whereClause = (client === 'postgres' ? '"' + key + '"' : key) + ' IN (' + parentValue + ')';

return [].concat((0, _toConsumableArray3.default)(result), [function (transaction) {
return transaction(tableName).del().whereRaw(whereClause);
}, model.recursiveDeletes(Bookshelf.knex(tableName).column(idAttribute).whereRaw(whereClause))]);
}, skipDependents ? [] : model.recursiveDeletes(Bookshelf.knex(tableName).column(model.prototype.idAttribute).whereRaw(whereClause))]);
}, []);

return (0, _lodash.flatten)((0, _lodash.compact)(queries)).reverse();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bookshelf-cascade-delete",
"version": "1.0.2",
"version": "1.0.3",
"description": "Cascade delete with Bookshelf.js",
"license": "MIT",
"author": {
Expand Down

0 comments on commit 93030cd

Please sign in to comment.