fixed issue when entity without id is requested during persistment

This commit is contained in:
Umed Khudoiberdiev 2016-11-23 23:09:28 +05:00
parent 6c36c38fdb
commit 0b0dbdebcc
3 changed files with 12 additions and 6 deletions

View File

@ -203,15 +203,19 @@ export class DatabaseEntityLoader<Entity extends ObjectLiteral> {
* Loads database entities for all loaded subjects which does not have database entities set.
*/
protected async loadDatabaseEntities(): Promise<void> {
const promises = this.loadedSubjects
const promises: Promise<any>[] = [];
this.loadedSubjects
.groupByEntityTargets()
.map(subjectGroup => {
.forEach(subjectGroup => {
const allIds = subjectGroup.subjects
.filter(subject => !subject.databaseEntity)
.map(subject => subject.mixedId);
.map(subject => subject.mixedId)
.filter(mixedId => mixedId !== undefined && mixedId !== null);
if (!allIds.length)
return;
const metadata = this.connection.getMetadata(subjectGroup.target);
return this.connection
const promise = this.connection
.getRepository<ObjectLiteral>(subjectGroup.target)
.findByIds(allIds, { alias: metadata.table.name, enabledOptions: ["RELATION_ID_VALUES"] })
.then(entities => {
@ -221,6 +225,8 @@ export class DatabaseEntityLoader<Entity extends ObjectLiteral> {
subject.databaseEntity = entity;
});
});
promises.push(promise);
});
await Promise.all(promises);

View File

@ -22,7 +22,7 @@ describe("insertion", function() {
// Specifications: persist
// -------------------------------------------------------------------------
it("basic insert functionality", () => Promise.all(connections.map(async connection => {
it.only("basic insert functionality", () => Promise.all(connections.map(async connection => {
const postRepository = connection.getRepository(Post);
let newPost = new Post();

View File

@ -84,7 +84,7 @@ export async function setupTestingConnections(options?: TestingConnectionOptions
entities: options && options.entities ? options.entities : [],
entitySchemas: options && options.entitySchemas ? options.entitySchemas : [],
logging: {
// logQueries: true, // uncomment for debugging
logQueries: true, // uncomment for debugging
logOnlyFailedQueries: true,
logFailedQueryError: true
},