-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Query builder update generates broken SQL #2849
Comments
I've figured this works:
But it seems really weird that typeorm won't let me set the id field directly. Also it shouldn't fail silently. Because of that I will let this issue open for further discussion. |
I think you have defined Try add @Column()
brandId: number; And it should worked as expected. Also this should work: .set({ brand: { id: brandId } }) |
yeah so we might need to report some error if user passed unknown properties in the object being passed within |
I think it should be good manner to throw error in case final map of values to update is empty. In Also It should be nice to allow update "columns generated by relations" as in this case where |
@vlapo I think we shall check both emptiness and wrong properties in. |
Sure I agree. But what about join column not defined in entity as property like Maybe we should allow update Example: @Entity()
export class Post {
@PrimaryGeneratedColumn()
id: number;
@ManyToOne(type => Author, author => author.posts)
@JoinColumn()
author: Author;
} const query = connection.manager
.createQueryBuilder()
.update(Post)
.set({ authorId: 2 })
.where({ id: 1 });
console.log(query.getSql()); This should be valid way to update author in post. |
no, I don't think so. This design isn't clear. What is In terms of this issue we only need to add those exceptions and close it. If we want to extend update query builder functionality, we need to create a separate issue and describe a new proposal of update query builder that covers all cases. |
Understand. But still I would love to see this case For this issue I will create PR and handle emptiness and wrong properties 👍 |
Issue type:
[x] bug report
Database system/driver:
[x]
postgres
TypeORM version:
[x]
latest
This logs:
Expected result:
Generated SQL to include object passed to
set
method.The text was updated successfully, but these errors were encountered: