Skip to content

Commit

Permalink
[Release] 0.36.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Mar 3, 2020
1 parent e181ec3 commit d3b10ad
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 155 deletions.
149 changes: 98 additions & 51 deletions dist/vuex-orm.common.js
Expand Up @@ -1528,6 +1528,10 @@ var BelongsToMany = /** @class */ (function (_super) {
*/
function BelongsToMany(model, related, pivot, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
/**
* The key name of the pivot data.
*/
_this.pivotKey = 'pivot';
_this.related = _this.model.relation(related);
_this.pivot = _this.model.relation(pivot);
_this.foreignPivotKey = foreignPivotKey;
Expand All @@ -1536,6 +1540,13 @@ var BelongsToMany = /** @class */ (function (_super) {
_this.relatedKey = relatedKey;
return _this;
}
/**
* Specify the custom pivot accessor to use for the relationship.
*/
BelongsToMany.prototype.as = function (accessor) {
this.pivotKey = accessor;
return this;
};
/**
* Define the normalizr schema for the relationship.
*/
Expand Down Expand Up @@ -1596,7 +1607,10 @@ var BelongsToMany = /** @class */ (function (_super) {
}
var related = relateds[record[_this.relatedPivotKey]];
if (related) {
records[id] = records[id].concat(related);
records[id] = records[id].concat(related.map(function (model) {
model[_this.pivotKey] = record;
return model;
}));
}
return records;
}, {});
Expand Down Expand Up @@ -1631,7 +1645,8 @@ var BelongsToMany = /** @class */ (function (_super) {
_this.pivot.primaryKey[1] === _this.foreignPivotKey ? parentId : relatedId
]);
var pivotRecord = data[_this.pivot.entity] ? data[_this.pivot.entity][pivotKey] : {};
data[_this.pivot.entity] = __assign(__assign({}, data[_this.pivot.entity]), (_a = {}, _a[pivotKey] = __assign(__assign({}, pivotRecord), (_b = { $id: pivotKey }, _b[_this.foreignPivotKey] = parentId, _b[_this.relatedPivotKey] = relatedId, _b)), _a));
var pivotData = data[_this.related.entity][id][_this.pivotKey] || {};
data[_this.pivot.entity] = __assign(__assign({}, data[_this.pivot.entity]), (_a = {}, _a[pivotKey] = __assign(__assign(__assign({}, pivotRecord), pivotData), (_b = { $id: pivotKey }, _b[_this.foreignPivotKey] = parentId, _b[_this.relatedPivotKey] = relatedId, _b)), _a));
});
};
return BelongsToMany;
Expand Down Expand Up @@ -1828,6 +1843,10 @@ var MorphToMany = /** @class */ (function (_super) {
*/
function MorphToMany(model, related, pivot, relatedId, id, type, parentKey, relatedKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
/**
* The key name of the pivot data.
*/
_this.pivotKey = 'pivot';
_this.related = _this.model.relation(related);
_this.pivot = _this.model.relation(pivot);
_this.relatedId = relatedId;
Expand All @@ -1837,6 +1856,13 @@ var MorphToMany = /** @class */ (function (_super) {
_this.relatedKey = relatedKey;
return _this;
}
/**
* Specify the custom pivot accessor to use for the relationship.
*/
MorphToMany.prototype.as = function (accessor) {
this.pivotKey = accessor;
return this;
};
/**
* Define the normalizr schema for the relationship.
*/
Expand Down Expand Up @@ -1896,7 +1922,10 @@ var MorphToMany = /** @class */ (function (_super) {
records[id] = [];
}
var related = relateds[record[_this.relatedId]];
records[id] = records[id].concat(related);
records[id] = records[id].concat(related.map(function (model) {
model[_this.pivotKey] = record;
return model;
}));
return records;
}, {});
};
Expand Down Expand Up @@ -1928,13 +1957,8 @@ var MorphToMany = /** @class */ (function (_super) {
var parentId = record[_this.parentKey];
var relatedId = data[_this.related.entity][id][_this.relatedKey];
var pivotKey = parentId + "_" + id + "_" + parent.entity;
data[_this.pivot.entity] = __assign(__assign({}, data[_this.pivot.entity]), (_a = {}, _a[pivotKey] = (_b = {
$id: pivotKey
},
_b[_this.relatedId] = relatedId,
_b[_this.id] = parentId,
_b[_this.type] = parent.entity,
_b), _a));
var pivotData = data[_this.related.entity][id][_this.pivotKey] || {};
data[_this.pivot.entity] = __assign(__assign({}, data[_this.pivot.entity]), (_a = {}, _a[pivotKey] = __assign(__assign({}, pivotData), (_b = { $id: pivotKey }, _b[_this.relatedId] = relatedId, _b[_this.id] = parentId, _b[_this.type] = parent.entity, _b)), _a));
});
};
return MorphToMany;
Expand All @@ -1947,6 +1971,10 @@ var MorphedByMany = /** @class */ (function (_super) {
*/
function MorphedByMany(model, related, pivot, relatedId, id, type, parentKey, relatedKey) {
var _this = _super.call(this, model) /* istanbul ignore next */ || this;
/**
* The key name of the pivot data.
*/
_this.pivotKey = 'pivot';
_this.related = _this.model.relation(related);
_this.pivot = _this.model.relation(pivot);
_this.relatedId = relatedId;
Expand All @@ -1956,6 +1984,13 @@ var MorphedByMany = /** @class */ (function (_super) {
_this.relatedKey = relatedKey;
return _this;
}
/**
* Specify the custom pivot accessor to use for the relationship.
*/
MorphedByMany.prototype.as = function (accessor) {
this.pivotKey = accessor;
return this;
};
/**
* Define the normalizr schema for the relationship.
*/
Expand Down Expand Up @@ -2016,7 +2051,10 @@ var MorphedByMany = /** @class */ (function (_super) {
records[id] = [];
}
var related = relateds[record[_this.id]];
records[id] = records[id].concat(related);
records[id] = records[id].concat(related.map(function (model) {
model[_this.pivotKey] = record;
return model;
}));
return records;
}, {});
};
Expand All @@ -2043,13 +2081,8 @@ var MorphedByMany = /** @class */ (function (_super) {
var _a, _b;
var parentId = record[_this.parentKey];
var pivotKey = id + "_" + parentId + "_" + _this.related.entity;
data[_this.pivot.entity] = __assign(__assign({}, data[_this.pivot.entity]), (_a = {}, _a[pivotKey] = (_b = {
$id: pivotKey
},
_b[_this.relatedId] = parentId,
_b[_this.id] = _this.model.getIdFromRecord(data[_this.related.entity][id]),
_b[_this.type] = _this.related.entity,
_b), _a));
var pivotData = data[_this.related.entity][id][_this.pivotKey] || {};
data[_this.pivot.entity] = __assign(__assign({}, data[_this.pivot.entity]), (_a = {}, _a[pivotKey] = __assign(__assign({}, pivotData), (_b = { $id: pivotKey }, _b[_this.relatedId] = parentId, _b[_this.id] = _this.model.getIdFromRecord(data[_this.related.entity][id]), _b[_this.type] = _this.related.entity, _b)), _a));
});
};
return MorphedByMany;
Expand Down Expand Up @@ -2342,6 +2375,12 @@ var Model = /** @class */ (function () {
Model.query = function () {
return this.getters('query')();
};
/**
* Check wether the associated database contains data.
*/
Model.exists = function () {
return this.query().exists();
};
/**
* Create new data with all fields filled by default values.
*/
Expand Down Expand Up @@ -4139,6 +4178,13 @@ var Query = /** @class */ (function () {
}
return this.item(this.hydrate(records[records.length - 1]));
};
/**
* Checks whether a result of the query chain exists.
*/
Query.prototype.exists = function () {
var records = this.select();
return records.length > 0;
};
/**
* Add a and where clause to the query.
*/
Expand Down Expand Up @@ -5162,39 +5208,6 @@ var RootMutations = {
delete: destroy$2
};

function use (plugin, options) {
if (options === void 0) { options = {}; }
var components = {
Model: Model,
Attribute: Attribute,
Type: Type,
Attr: Attr,
String: String$1,
Number: Number,
Boolean: Boolean,
Uid: Uid$1,
Relation: Relation,
HasOne: HasOne,
BelongsTo: BelongsTo,
HasMany: HasMany,
HasManyBy: HasManyBy,
BelongsToMany: BelongsToMany,
HasManyThrough: HasManyThrough,
MorphTo: MorphTo,
MorphOne: MorphOne,
MorphMany: MorphMany,
MorphToMany: MorphToMany,
MorphedByMany: MorphedByMany,
Getters: Getters,
Actions: Actions,
RootGetters: RootGetters,
RootActions: RootActions,
RootMutations: RootMutations,
Query: Query
};
plugin.install(components, options);
}

var ProcessStrategy = /** @class */ (function () {
function ProcessStrategy() {
}
Expand Down Expand Up @@ -5587,6 +5600,40 @@ var Database = /** @class */ (function () {
return Database;
}());

function use (plugin, options) {
if (options === void 0) { options = {}; }
var components = {
Model: Model,
Attribute: Attribute,
Type: Type,
Attr: Attr,
String: String$1,
Number: Number,
Boolean: Boolean,
Uid: Uid$1,
Relation: Relation,
HasOne: HasOne,
BelongsTo: BelongsTo,
HasMany: HasMany,
HasManyBy: HasManyBy,
BelongsToMany: BelongsToMany,
HasManyThrough: HasManyThrough,
MorphTo: MorphTo,
MorphOne: MorphOne,
MorphMany: MorphMany,
MorphToMany: MorphToMany,
MorphedByMany: MorphedByMany,
Getters: Getters,
Actions: Actions,
RootGetters: RootGetters,
RootActions: RootActions,
RootMutations: RootMutations,
Query: Query,
Database: Database
};
plugin.install(components, options);
}

var index_cjs = {
install: install,
use: use,
Expand Down

0 comments on commit d3b10ad

Please sign in to comment.