New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composite join key with metadata example incomplete #529
Labels
bug
Something isn't working
Comments
I am also having this issue base.entity.ts @ObjectType()
export abstract class Base {
@Field((type) => ID)
@PrimaryKey({ length: 36 })
uuid = v4();
@Property()
createdAt = new Date();
@Property({ onUpdate: () => new Date() })
updatedAt = new Date();
} user.entity.ts @ObjectType()
@Entity()
export class User extends Base {
@Unique()
@Property()
email!: string;
@HideField()
@Property({ length: 60, hidden: true })
password!: string;
@Property()
firstName!: string;
@Property()
lastName!: string;
@Field((type) => [UserToStore])
@OneToMany(
() => UserToStore,
(metaStore) => metaStore.user
)
metaStores: Collection<UserToStore> = new Collection<UserToStore>(this);
} store.entity.ts @ObjectType()
@Entity()
export class Store extends Base {
@Property()
name!: string;
@Property()
address?: string;
@Field((type) => [UserToStore])
@OneToMany(
() => UserToStore,
(metaUser) => metaUser.store
)
metaUsers: Collection<UserToStore> = new Collection<UserToStore>(this);
} user-to-store.entity.ts export enum UserStoreRole {
OWNER = 'owner',
MANAGER = 'manager'
}
registerEnumType(UserStoreRole, {
name: 'UserStoreRole'
});
@ObjectType()
@Entity()
export class UserToStore {
@ManyToOne(() => User, { primary: true })
user!: User;
@ManyToOne(() => Store, { primary: true })
store!: Store;
@Field((type) => UserStoreRole)
@Enum()
role!: UserStoreRole;
[PrimaryKeyType]: [string, string];
} In my code I call a function like this async findOne(uuid: string) {
return this.userRepository.findOne({
uuid: uuid
});
} Later I call another function using the object returned by the above function await user.metaStores.init(); And I get this error
|
willsoto
changed the title
Composite join key with metadata example buggy or incomplete
Composite join key with metadata example incomplete
May 1, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When following the example given here for using a composite PK, the following error is raised when trying to load the related entities:
(Note that my code's models are different in name only. I've followed the docs and rechecked all my code extensively, I will be using the naming in the docs here).
The one major(?) difference is that I specify
tableName
for all my entities, which differs from the auto-generated one. I've also confirmed that the tables themselves are correct.I was able to verify the queries are correct, so the sql being generated is what I would expect. I also ran the generated sql and it was 👍 . This seems to be an issue with validation in the orm.
Stack trace
To Reproduce
Steps to reproduce the behavior:
Expected behavior
If the entities are configured correctly, no error should be thrown.
If the entities are not configured correctly, a more descriptive error should be thrown.
Additional context
I am using MikroORM via it's NestJS integration.
Some other things I have tried in an effort to get it working, all of them yielding the same error message:
I've also tried specifying
fieldName
andinversedBy
on theOrderItem.order
Versions
The text was updated successfully, but these errors were encountered: