You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Composite primary key causes select query syntax issues with findOne()
Stack trace
SyntaxErrorException: select `e0`.* from `d` as `e0` where (`e0`.`a_id`, `e0`.`a_c_id`) = values ('2f2837fe-ebaf-45eb-a858-2789ff675d21', 'a984c575-0bc7-4fc8-9390-849c7e60430d') limit 1 - SQLITE_ERROR: near "values": syntax error
at SqliteExceptionConverter.convertException (C:\Users\ravin\Desktop\mikro-orm\packages\sqlite\src\SqliteExceptionConverter.js:38:20)
at SqliteDriver.convertException (C:\Users\ravin\Desktop\mikro-orm\packages\core\src\drivers\DatabaseDriver.js:171:54)
at C:\Users\ravin\Desktop\mikro-orm\packages\core\src\drivers\DatabaseDriver.js:175:24
at SqliteDriver.find (C:\Users\ravin\Desktop\mikro-orm\packages\knex\src\AbstractSqlDriver.js:42:24)
at SqliteDriver.findOne (C:\Users\ravin\Desktop\mikro-orm\packages\knex\src\AbstractSqlDriver.js:56:21)
at SqlEntityManager.findOne (C:\Users\ravin\Desktop\mikro-orm\packages\core\src\EntityManager.js:192:22)
previous Error: select `e0`.* from `d` as `e0` where (`e0`.`a_id`, `e0`.`a_c_id`) = values ('2f2837fe-ebaf-45eb-a858-2789ff675d21', 'a984c575-0bc7-4fc8-9390-849c7e60430d') limit 1 - SQLITE_ERROR: near "values": syntax error
To Reproduce
import {
Collection,
Entity,
ManyToOne,
MikroORM,
OneToMany,
OneToOne,
PrimaryKey,
} from '@mikro-orm/core';
import { AbstractSqlDriver } from '@mikro-orm/knex';
import { v4 } from 'uuid';
@Entity()
export class D {
@PrimaryKey()
id = v4();
@ManyToOne({ entity: 'A' })
a!: any;
}
@Entity()
export class C {
@PrimaryKey()
id = v4();
}
@Entity()
export class B {
@PrimaryKey()
id = v4();
}
@Entity()
export class A {
@OneToOne({ entity: 'B', joinColumn: 'id', primary: true })
id!: B;
@ManyToOne({ entity: 'C', primary: true })
c!: C;
@OneToMany({ entity: 'D', mappedBy: 'a', eager: true })
d = new Collection<D>(this);
}
describe('GH issue 1157', () => {
let orm: MikroORM<AbstractSqlDriver>;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [A, B, C, D],
dbName: ':memory:',
type: 'sqlite',
});
await orm.getSchemaGenerator().createSchema();
});
afterAll(() => orm.close(true));
test('Composite key gives issues with select query', async () => {
const c = orm.em.create(C, {});
const b = orm.em.create(B, {});
const a = orm.em.create(A, {
id: b,
c,
});
orm.em.persistAndFlush(a);
// SyntaxErrorException
orm.em.findOne(D, { a });
orm.em.clear();
// Adding expect ignores the syntax error so not adding a assert
});
});
Expected behavior
Working findOne() with composite keys.
Versions
Dependency
Version
node
12.18.4
typescript
4.0.3
mikro-orm
4.3.3-dev.17
mikro-orm/sqlite
4.3.3-dev.17
The text was updated successfully, but these errors were encountered:
Describe the bug
Composite primary key causes select query syntax issues with findOne()
Stack trace
To Reproduce
Expected behavior
Working findOne() with composite keys.
Versions
The text was updated successfully, but these errors were encountered: