-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Closed
Labels
Description
Issue description
when defining a joinTable on any entity, EntityPropertyNotFoundError is thrown when joining any relation directly from that table, that table also seems to have empty metadata.relations
Expected Behavior
joining relations directly from joinTable should not throw EntityPropertyNotFoundError
Actual Behavior
error thrown EntityPropertyNotFoundError: Property "property" was not found in ""
Steps to reproduce
// entities.ts
import { EntitySchema } from 'typeorm';
interface DocumentRelation {
documentRelationId: number;
documentId: number;
userId?: number;
document?: Document;
}
interface Document {
documentId: number;
documentRelation?: DocumentRelation[];
}
interface User {
userId: number;
documents?: Document[];
}
export const userEntitySchema = new EntitySchema<User>({
name: 'user',
columns: {
userId: { type: Number, primary: true, generated: 'increment', name: 'user_id' },
},
relations: {
documents: {
type: 'many-to-many',
target: 'document',
joinTable: {
name: 'document_relation',
joinColumn: {
name: 'user_id',
referencedColumnName: 'userId',
},
inverseJoinColumn: {
name: 'document_id',
referencedColumnName: 'documentId',
},
},
},
},
});
export const documentEntitySchema = new EntitySchema<Document>({
name: 'document',
columns: {
documentId: { type: Number, primary: true, generated: 'increment', name: 'document_id' },
},
relations: {
documentRelation: {
type: 'one-to-many',
target: 'document_relation',
inverseSide: 'document',
joinColumn: {
name: 'document_id',
referencedColumnName: 'documentId',
},
},
},
});
export const documentRelationEntitySchema = new EntitySchema<DocumentRelation>({
name: 'document_relation',
columns: {
documentRelationId: { type: Number, primary: true, generated: 'increment', name: 'document_relation_id' },
documentId: { type: Number, name: 'document_id' },
userId: { type: Number, name: 'user_id', nullable: true },
},
relations: {
document: {
type: 'many-to-one',
target: 'document',
inverseSide: 'documentRelation',
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
joinColumn: {
name: 'document_id',
referencedColumnName: 'documentId',
},
},
},
});
// index.ts
import { DataSource } from 'typeorm';
import { documentRelationEntitySchema } from './entities';
async function run() {
const dataSource = new DataSource({
url: 'postgres://postgres:postgres@localhost:5432/db',
entities: ['./entities.ts'],
type: 'postgres',
synchronize: false,
});
await dataSource.initialize();
const repository = dataSource.manager.getRepository(documentRelationEntitySchema);
console.log(repository.metadata.relations); // []
await repository.find({ where: { userId: 2030 }, relations: ['document'] }); // throws EntityPropertyNotFoundError: Property "document" was not found in ""
}
run();My Environment
| Dependency | Version |
|---|---|
| Operating System | macOS 13.0.1 |
| Node.js version | 18.18 |
| Typescript version | 5.2.2 |
| TypeORM version | 0.3.13 |
Additional Context
This bug seems to be a direct regression from 0.3.13
Relevant Database Driver(s)
- aurora-mysql
- aurora-postgres
- better-sqlite3
- cockroachdb
- cordova
- expo
- mongodb
- mysql
- nativescript
- oracle
- postgres
- react-native
- sap
- spanner
- sqlite
- sqlite-abstract
- sqljs
- sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, but I don't know how to start. I would need guidance.