UNPKG

@kitmi/data

Version:

Jacaranda Framework Data Access Model

34 lines (33 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, /** * A rule specifies the change of state will be tracked automatically. * @module EntityFeatureRuntime_AutoCreate */ "default", { enumerable: true, get: function() { return _default; } }); const _utils = require("@kitmi/utils"); const _Rules = /*#__PURE__*/ _interop_require_default(require("../Rules")); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const _default = { [_Rules.default.RULE_BEFORE_CREATE]: async (feature, entity, context)=>{ const RelatedEntity = entity.getRelatedEntity(feature.relation); const initData = entity._translateValue(feature.initData, context.options); const result = await RelatedEntity.create_(initData); const assocInfo = entity.meta.associations[feature.relation]; // only belongsTo and refersTo has type if (assocInfo.type) { context.latest[feature.relation] = result.data[assocInfo.field]; } } }; //# sourceMappingURL=createBefore.js.map