mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixed issue when entity without id is requested during persistment
This commit is contained in:
parent
6c36c38fdb
commit
0b0dbdebcc
@ -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);
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user