'Cannot query across one-to-many for property property typeorm when updating entity
i am trying to update an entity with the related value, but i get the above error, i dont know what I am doing wrong.
@Entity('Properties')
class Property extends BaseEntity {
@PrimaryGeneratedColumn()
_id!: string;
@ManyToOne(() => Host, (host) => host.property, {
})
@JoinColumn()
host!: Host;
static async createProperty(data: any, req: any): Promise<any> {
const Manager = this.getRepository().manager;
return Manager.transaction(async transactionalEntityManager => {
const room = transactionalEntityManager.create(Room, data.rooms);
const property = transactionalEntityManager.create(Property, data);
await transactionalEntityManager.save(room);
await transactionalEntityManager
.createQueryBuilder()
.update(Host)
.set({ property: property })
.where("_id = :id", { id: 1 })
.execute();
property.room = room;
await transactionalEntityManager.save(property);
console.log('daa', property, room);
return property;
})
};
Or when i use this
const user = await Host.update(req.user.host._id, { property: property });
@Entity('hosts')
class Host extends BaseEntity {
@PrimaryGeneratedColumn()
_id!: string;
@OneToMany(() => Property, property => property.host, {
cascade: true,
eager: true,
})
property!: Property[]
probably I am just doing something stupid any help, please.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|