typeorm 0.3.10-dev.f24b262 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/cli-ts-node-commonjs.js +0 -0
- package/browser/cli-ts-node-esm.js +0 -0
- package/browser/data-source/BaseDataSourceOptions.d.ts +4 -0
- package/browser/data-source/BaseDataSourceOptions.js.map +1 -1
- package/browser/decorator/options/RelationOptions.d.ts +5 -2
- package/browser/decorator/options/RelationOptions.js.map +1 -1
- package/browser/driver/aurora-mysql/AuroraMysqlConnectionOptions.d.ts +1 -0
- package/browser/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
- package/browser/driver/aurora-postgres/AuroraPostgresConnectionOptions.d.ts +1 -0
- package/browser/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +1 -0
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/browser/driver/capacitor/CapacitorConnectionOptions.d.ts +1 -0
- package/browser/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachDriver.js +1 -0
- package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/browser/driver/cordova/CordovaConnectionOptions.d.ts +1 -0
- package/browser/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/browser/driver/expo/ExpoConnectionOptions.d.ts +1 -0
- package/browser/driver/expo/ExpoConnectionOptions.js.map +1 -1
- package/browser/driver/mongodb/MongoConnectionOptions.d.ts +0 -4
- package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/browser/driver/mysql/MysqlDriver.js +1 -1
- package/browser/driver/mysql/MysqlDriver.js.map +1 -1
- package/browser/driver/nativescript/NativescriptConnectionOptions.d.ts +1 -0
- package/browser/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
- package/browser/driver/oracle/OracleDriver.js +2 -0
- package/browser/driver/oracle/OracleDriver.js.map +1 -1
- package/browser/driver/postgres/PostgresDriver.js +1 -0
- package/browser/driver/postgres/PostgresDriver.js.map +1 -1
- package/browser/driver/react-native/ReactNativeConnectionOptions.d.ts +1 -0
- package/browser/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/browser/driver/sap/SapConnectionOptions.d.ts +1 -0
- package/browser/driver/sap/SapConnectionOptions.js.map +1 -1
- package/browser/driver/spanner/SpannerConnectionOptions.d.ts +1 -0
- package/browser/driver/spanner/SpannerConnectionOptions.js.map +1 -1
- package/browser/driver/sqlite/SqliteConnectionOptions.d.ts +1 -0
- package/browser/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/browser/driver/sqljs/SqljsConnectionOptions.d.ts +1 -0
- package/browser/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/browser/driver/sqljs/SqljsDriver.d.ts +1 -0
- package/browser/driver/sqljs/SqljsDriver.js +3 -1
- package/browser/driver/sqljs/SqljsDriver.js.map +1 -1
- package/browser/driver/sqljs/SqljsQueryRunner.js +3 -1
- package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -0
- package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/browser/entity-schema/EntitySchemaRelationOptions.d.ts +4 -2
- package/browser/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/browser/metadata/RelationMetadata.d.ts +4 -2
- package/browser/metadata/RelationMetadata.js.map +1 -1
- package/browser/persistence/subject-builder/OneToManySubjectBuilder.js +30 -27
- package/browser/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.js +1 -1
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/cli-ts-node-commonjs.js +0 -0
- package/cli-ts-node-esm.js +0 -0
- package/cli.js +0 -0
- package/data-source/BaseDataSourceOptions.d.ts +4 -0
- package/data-source/BaseDataSourceOptions.js.map +1 -1
- package/decorator/options/RelationOptions.d.ts +5 -2
- package/decorator/options/RelationOptions.js.map +1 -1
- package/driver/aurora-mysql/AuroraMysqlConnectionOptions.d.ts +1 -0
- package/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
- package/driver/aurora-postgres/AuroraPostgresConnectionOptions.d.ts +1 -0
- package/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +1 -0
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/driver/capacitor/CapacitorConnectionOptions.d.ts +1 -0
- package/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
- package/driver/cockroachdb/CockroachDriver.js +1 -0
- package/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/driver/cordova/CordovaConnectionOptions.d.ts +1 -0
- package/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/driver/expo/ExpoConnectionOptions.d.ts +1 -0
- package/driver/expo/ExpoConnectionOptions.js.map +1 -1
- package/driver/mongodb/MongoConnectionOptions.d.ts +0 -4
- package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/driver/mysql/MysqlDriver.js +1 -1
- package/driver/mysql/MysqlDriver.js.map +1 -1
- package/driver/nativescript/NativescriptConnectionOptions.d.ts +1 -0
- package/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
- package/driver/oracle/OracleDriver.js +2 -0
- package/driver/oracle/OracleDriver.js.map +1 -1
- package/driver/postgres/PostgresDriver.js +1 -0
- package/driver/postgres/PostgresDriver.js.map +1 -1
- package/driver/react-native/ReactNativeConnectionOptions.d.ts +1 -0
- package/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/driver/sap/SapConnectionOptions.d.ts +1 -0
- package/driver/sap/SapConnectionOptions.js.map +1 -1
- package/driver/spanner/SpannerConnectionOptions.d.ts +1 -0
- package/driver/spanner/SpannerConnectionOptions.js.map +1 -1
- package/driver/sqlite/SqliteConnectionOptions.d.ts +1 -0
- package/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/driver/sqljs/SqljsConnectionOptions.d.ts +1 -0
- package/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/driver/sqljs/SqljsDriver.d.ts +1 -0
- package/driver/sqljs/SqljsDriver.js +3 -1
- package/driver/sqljs/SqljsDriver.js.map +1 -1
- package/driver/sqljs/SqljsQueryRunner.js +3 -1
- package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -0
- package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/entity-schema/EntitySchemaRelationOptions.d.ts +4 -2
- package/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/metadata/RelationMetadata.d.ts +4 -2
- package/metadata/RelationMetadata.js.map +1 -1
- package/package.json +274 -1
- package/persistence/subject-builder/OneToManySubjectBuilder.js +30 -27
- package/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
- package/query-builder/SelectQueryBuilder.js +1 -1
- package/query-builder/SelectQueryBuilder.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/persistence/subject-builder/OneToManySubjectBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAG9D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,uBAAuB;IAChC,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,YAAsB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;IAAG,CAAC;IAE7C,wEAAwE;IACxE,iBAAiB;IACjB,wEAAwE;IAExE;;OAEG;IACH,KAAK;QACD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC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ACnD;iBAAM,IACH,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,aAAa,EAC9D;gBACE,2BAA2B,CAAC,gBAAgB,GAAG,IAAI,CAAA;aACtD;YAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;QACnD,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","file":"OneToManySubjectBuilder.js","sourcesContent":["import { Subject } from \"../Subject\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { RelationMetadata } from \"../../metadata/RelationMetadata\"\n\n/**\n * Builds operations needs to be executed for one-to-many relations of the given subjects.\n *\n * by example: post contains one-to-many relation with category in the property called \"categories\", e.g.\n * @OneToMany(type => Category, category => category.post) categories: Category[]\n * If user adds categories into the post and saves post we need to bind them.\n * This operation requires updation of category table since its owner of the relation and contains a join column.\n *\n * note: this class shares lot of things with OneToOneInverseSideOperationBuilder, so when you change this class\n * make sure to reflect changes there as well.\n */\nexport class OneToManySubjectBuilder {\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(protected subjects: Subject[]) {}\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds all required operations.\n */\n build(): void {\n this.subjects.forEach((subject) => {\n subject.metadata.oneToManyRelations.forEach((relation) => {\n // skip relations for which persistence is disabled\n if (relation.persistenceEnabled === false) return\n\n this.buildForSubjectRelation(subject, relation)\n })\n })\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds operations for a given subject and relation.\n *\n * by example: subject is \"post\" entity we are saving here and relation is \"categories\" inside it here.\n */\n protected buildForSubjectRelation(\n subject: Subject,\n relation: RelationMetadata,\n ) {\n // prepare objects (relation id maps) for the database entity\n // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,\n // particularly their relation ids, e.g. category ids stored in the database\n\n // in most cases relatedEntityDatabaseValues will contain only the entity key properties.\n // this is because subject.databaseEntity contains relations with loaded relation ids only.\n // however if the entity uses the afterLoad hook to calculate any properties, the fetched \"key object\" might include ADDITIONAL properties.\n // to handle such situations, we pass the data to relation.inverseEntityMetadata.getEntityIdMap to extract the key without any other properties.\n\n let relatedEntityDatabaseRelationIds: ObjectLiteral[] = []\n if (subject.databaseEntity) {\n // related entities in the database can exist only if this entity (post) is saved\n const relatedEntityDatabaseRelation: ObjectLiteral[] | undefined =\n relation.getEntityValue(subject.databaseEntity)\n if (relatedEntityDatabaseRelation) {\n relatedEntityDatabaseRelationIds =\n relatedEntityDatabaseRelation.map(\n (entity) =>\n relation.inverseEntityMetadata.getEntityIdMap(\n entity,\n )!,\n )\n }\n }\n\n // get related entities of persisted entity\n // by example: get categories from the passed to persist post entity\n let relatedEntities: ObjectLiteral[] = relation.getEntityValue(\n subject.entity!,\n )\n if (relatedEntities === null)\n // we treat relations set to null as removed, so we don't skip it\n relatedEntities = [] as ObjectLiteral[]\n if (relatedEntities === undefined)\n // if relation is undefined then nothing to update\n return\n\n // extract only relation ids from the related entities, since we only need them for comparison\n // by example: extract from categories only relation ids (category id, or let's say category title, depend on join column options)\n const relatedPersistedEntityRelationIds: ObjectLiteral[] = []\n relatedEntities.forEach((relatedEntity) => {\n // by example: relatedEntity is a category here\n let relationIdMap =\n relation.inverseEntityMetadata!.getEntityIdMap(relatedEntity) // by example: relationIdMap is category.id map here, e.g. { id: ... }\n\n // try to find a subject of this related entity, maybe it was loaded or was marked for persistence\n let relatedEntitySubject = this.subjects.find((subject) => {\n return subject.entity === relatedEntity\n })\n\n // if subject with entity was found take subject identifier as relation id map since it may contain extra properties resolved\n if (relatedEntitySubject)\n relationIdMap = relatedEntitySubject.identifier\n\n // if relationIdMap is undefined then it means user binds object which is not saved in the database yet\n // by example: if post contains categories which does not have ids yet (because they are new)\n // it means they are always newly inserted and relation update operation always must be created for them\n // it does not make sense to perform difference operation for them for both add and remove actions\n if (!relationIdMap) {\n // we decided to remove this error because it brings complications when saving object with non-saved entities\n // if (!relatedEntitySubject)\n // throw new TypeORMError(`One-to-many relation \"${relation.entityMetadata.name}.${relation.propertyPath}\" contains ` +\n // `entities which do not exist in the database yet, thus they cannot be bind in the database. ` +\n // `Please setup cascade insertion or save entities before binding it.`);\n if (!relatedEntitySubject) return\n\n // okay, so related subject exist and its marked for insertion, then add a new change map\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject,\n })\n\n return\n }\n\n // check if this binding really exist in the database\n // by example: find our category if its already bind in the database\n const relationIdInDatabaseSubjectRelation =\n relatedEntityDatabaseRelationIds.find(\n (relatedDatabaseEntityRelationId) => {\n return OrmUtils.compareIds(\n relationIdMap,\n relatedDatabaseEntityRelationId,\n )\n },\n )\n\n // if relationIdMap DOES NOT exist in the subject's relation in the database it means its a new relation and we need to \"bind\" them\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n if (!relationIdInDatabaseSubjectRelation) {\n // if there is no relatedEntitySubject then it means \"category\" wasn't persisted,\n // but since we are going to update \"category\" table (since its an owning side of relation with join column)\n // we create a new subject here:\n if (!relatedEntitySubject) {\n relatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n canBeUpdated: true,\n identifier: relationIdMap,\n })\n this.subjects.push(relatedEntitySubject)\n }\n\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject,\n })\n }\n\n // if related entity has relation id then we add it to the list of relation ids\n // this list will be used later to compare with database relation ids to find a difference\n // what exist in this array and does not exist in the database are newly inserted relations\n // what does not exist in this array, but exist in the database are removed relations\n // removed relations are set to null from inverse side of relation\n relatedPersistedEntityRelationIds.push(relationIdMap)\n })\n\n // find what related entities were added and what were removed based on difference between what we save and what database has\n EntityMetadata.difference(\n relatedEntityDatabaseRelationIds,\n relatedPersistedEntityRelationIds,\n ).forEach((removedRelatedEntityRelationId) => {\n // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind\n\n // todo: probably we can improve this in the future by finding entity with column those values,\n // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns\n // we create a new subject which operations will be executed in subject operation executor\n const removedRelatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n identifier: removedRelatedEntityRelationId,\n })\n\n if (\n !relation.inverseRelation ||\n relation.inverseRelation.orphanedRowAction === \"nullify\"\n ) {\n removedRelatedEntitySubject.canBeUpdated = true\n removedRelatedEntitySubject.changeMaps = [\n {\n relation: relation.inverseRelation!,\n value: null,\n },\n ]\n } else if (\n relation.inverseRelation.orphanedRowAction === \"delete\"\n ) {\n removedRelatedEntitySubject.mustBeRemoved = true\n } else if (\n relation.inverseRelation.orphanedRowAction === \"soft-delete\"\n ) {\n removedRelatedEntitySubject.canBeSoftRemoved = true\n }\n\n this.subjects.push(removedRelatedEntitySubject)\n })\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/persistence/subject-builder/OneToManySubjectBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAG9D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,uBAAuB;IAChC,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,YAAsB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;IAAG,CAAC;IAE7C,wEAAwE;IACxE,iBAAiB;IACjB,wEAAwE;IA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C,KAAK,EAAE,IAAI;yBACd;qBACJ,CAAA;iBACJ;qBAAM,IACH,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,QAAQ,EACzD;oBACE,2BAA2B,CAAC,aAAa,GAAG,IAAI,CAAA;iBACnD;qBAAM,IACH,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,aAAa,EAC9D;oBACE,2BAA2B,CAAC,gBAAgB,GAAG,IAAI,CAAA;iBACtD;gBAED,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;YACnD,CAAC,CAAC,CAAA;SACL;IACL,CAAC;CACJ","file":"OneToManySubjectBuilder.js","sourcesContent":["import { Subject } from \"../Subject\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { RelationMetadata } from \"../../metadata/RelationMetadata\"\n\n/**\n * Builds operations needs to be executed for one-to-many relations of the given subjects.\n *\n * by example: post contains one-to-many relation with category in the property called \"categories\", e.g.\n * @OneToMany(type => Category, category => category.post) categories: Category[]\n * If user adds categories into the post and saves post we need to bind them.\n * This operation requires updation of category table since its owner of the relation and contains a join column.\n *\n * note: this class shares lot of things with OneToOneInverseSideOperationBuilder, so when you change this class\n * make sure to reflect changes there as well.\n */\nexport class OneToManySubjectBuilder {\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(protected subjects: Subject[]) {}\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds all required operations.\n */\n build(): void {\n this.subjects.forEach((subject) => {\n subject.metadata.oneToManyRelations.forEach((relation) => {\n // skip relations for which persistence is disabled\n if (relation.persistenceEnabled === false) return\n\n this.buildForSubjectRelation(subject, relation)\n })\n })\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds operations for a given subject and relation.\n *\n * by example: subject is \"post\" entity we are saving here and relation is \"categories\" inside it here.\n */\n protected buildForSubjectRelation(\n subject: Subject,\n relation: RelationMetadata,\n ) {\n // prepare objects (relation id maps) for the database entity\n // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,\n // particularly their relation ids, e.g. category ids stored in the database\n\n // in most cases relatedEntityDatabaseValues will contain only the entity key properties.\n // this is because subject.databaseEntity contains relations with loaded relation ids only.\n // however if the entity uses the afterLoad hook to calculate any properties, the fetched \"key object\" might include ADDITIONAL properties.\n // to handle such situations, we pass the data to relation.inverseEntityMetadata.getEntityIdMap to extract the key without any other properties.\n\n let relatedEntityDatabaseRelationIds: ObjectLiteral[] = []\n if (subject.databaseEntity) {\n // related entities in the database can exist only if this entity (post) is saved\n const relatedEntityDatabaseRelation: ObjectLiteral[] | undefined =\n relation.getEntityValue(subject.databaseEntity)\n if (relatedEntityDatabaseRelation) {\n relatedEntityDatabaseRelationIds =\n relatedEntityDatabaseRelation.map(\n (entity) =>\n relation.inverseEntityMetadata.getEntityIdMap(\n entity,\n )!,\n )\n }\n }\n\n // get related entities of persisted entity\n // by example: get categories from the passed to persist post entity\n let relatedEntities: ObjectLiteral[] = relation.getEntityValue(\n subject.entity!,\n )\n if (relatedEntities === null)\n // we treat relations set to null as removed, so we don't skip it\n relatedEntities = [] as ObjectLiteral[]\n if (relatedEntities === undefined)\n // if relation is undefined then nothing to update\n return\n\n // extract only relation ids from the related entities, since we only need them for comparison\n // by example: extract from categories only relation ids (category id, or let's say category title, depend on join column options)\n const relatedPersistedEntityRelationIds: ObjectLiteral[] = []\n relatedEntities.forEach((relatedEntity) => {\n // by example: relatedEntity is a category here\n let relationIdMap =\n relation.inverseEntityMetadata!.getEntityIdMap(relatedEntity) // by example: relationIdMap is category.id map here, e.g. { id: ... }\n\n // try to find a subject of this related entity, maybe it was loaded or was marked for persistence\n let relatedEntitySubject = this.subjects.find((subject) => {\n return subject.entity === relatedEntity\n })\n\n // if subject with entity was found take subject identifier as relation id map since it may contain extra properties resolved\n if (relatedEntitySubject)\n relationIdMap = relatedEntitySubject.identifier\n\n // if relationIdMap is undefined then it means user binds object which is not saved in the database yet\n // by example: if post contains categories which does not have ids yet (because they are new)\n // it means they are always newly inserted and relation update operation always must be created for them\n // it does not make sense to perform difference operation for them for both add and remove actions\n if (!relationIdMap) {\n // we decided to remove this error because it brings complications when saving object with non-saved entities\n // if (!relatedEntitySubject)\n // throw new TypeORMError(`One-to-many relation \"${relation.entityMetadata.name}.${relation.propertyPath}\" contains ` +\n // `entities which do not exist in the database yet, thus they cannot be bind in the database. ` +\n // `Please setup cascade insertion or save entities before binding it.`);\n if (!relatedEntitySubject) return\n\n // okay, so related subject exist and its marked for insertion, then add a new change map\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject,\n })\n\n return\n }\n\n // check if this binding really exist in the database\n // by example: find our category if its already bind in the database\n const relationIdInDatabaseSubjectRelation =\n relatedEntityDatabaseRelationIds.find(\n (relatedDatabaseEntityRelationId) => {\n return OrmUtils.compareIds(\n relationIdMap,\n relatedDatabaseEntityRelationId,\n )\n },\n )\n\n // if relationIdMap DOES NOT exist in the subject's relation in the database it means its a new relation and we need to \"bind\" them\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n if (!relationIdInDatabaseSubjectRelation) {\n // if there is no relatedEntitySubject then it means \"category\" wasn't persisted,\n // but since we are going to update \"category\" table (since its an owning side of relation with join column)\n // we create a new subject here:\n if (!relatedEntitySubject) {\n relatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n canBeUpdated: true,\n identifier: relationIdMap,\n })\n this.subjects.push(relatedEntitySubject)\n }\n\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject,\n })\n }\n\n // if related entity has relation id then we add it to the list of relation ids\n // this list will be used later to compare with database relation ids to find a difference\n // what exist in this array and does not exist in the database are newly inserted relations\n // what does not exist in this array, but exist in the database are removed relations\n // removed relations are set to null from inverse side of relation\n relatedPersistedEntityRelationIds.push(relationIdMap)\n })\n\n // find what related entities were added and what were removed based on difference between what we save and what database has\n if (relation.inverseRelation?.orphanedRowAction !== \"disable\") {\n EntityMetadata.difference(\n relatedEntityDatabaseRelationIds,\n relatedPersistedEntityRelationIds,\n ).forEach((removedRelatedEntityRelationId) => {\n // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind\n\n // todo: probably we can improve this in the future by finding entity with column those values,\n // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns\n // we create a new subject which operations will be executed in subject operation executor\n const removedRelatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n identifier: removedRelatedEntityRelationId,\n })\n\n if (\n !relation.inverseRelation ||\n relation.inverseRelation.orphanedRowAction === \"nullify\"\n ) {\n removedRelatedEntitySubject.canBeUpdated = true\n removedRelatedEntitySubject.changeMaps = [\n {\n relation: relation.inverseRelation!,\n value: null,\n },\n ]\n } else if (\n relation.inverseRelation.orphanedRowAction === \"delete\"\n ) {\n removedRelatedEntitySubject.mustBeRemoved = true\n } else if (\n relation.inverseRelation.orphanedRowAction === \"soft-delete\"\n ) {\n removedRelatedEntitySubject.canBeSoftRemoved = true\n }\n\n this.subjects.push(removedRelatedEntitySubject)\n })\n }\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -2109,7 +2109,7 @@ export class SelectQueryBuilder extends QueryBuilder {
|
|
|
2109
2109
|
// this.addSelect(alias + "." + propertyPath);
|
|
2110
2110
|
}
|
|
2111
2111
|
else if (embed) {
|
|
2112
|
-
this.buildSelect(select[key], metadata, alias,
|
|
2112
|
+
this.buildSelect(select[key], metadata, alias, propertyPath);
|
|
2113
2113
|
// } else if (relation) {
|
|
2114
2114
|
// const joinAlias = alias + "_" + relation.propertyName;
|
|
2115
2115
|
// const existJoin = this.joins.find(join => join.alias === joinAlias);
|