Using plain properties (not columns) in entity classes
See original GitHub issueHello, my issue would be the same as https://github.com/typeorm/typeorm/issues/3569
@Entity()
export class User extends Base{
@Column('varchar', { length: 255, unique: true })
@IsEmail({}, { message: "Invalid email." })
@IsUnique()
email: string;
@Column('varchar', { length: 255 })
@MinLength(6, { message: "Password must have at least 6 characters" })
password: string;
@Column('varchar', { length: 255 })
salt: string;
@Column('varchar', { length: 255 })
role: string;
password_changed: number = 0;
@BeforeUpdate()
setDataBeforeUpdate(){
if (this.password_changed){
this.password = PasswordHelper.hashString(this.password, this.salt);
}
}
}
Let’s take the above piece of code… i want the password_changed field to not be a column…just a plain old property for this class. The problem is that on update
const repo: Repository<User> = getRepository(User);
await repo.update(row.id, row).then().catch( (e) => { throw e; });
i get this error
EntityColumnNotFound: No entity column "password_changed" was found.
at new EntityColumnNotFound (.../src/error/EntityColumnNotFound.ts:8:9)
at .../src/query-builder/UpdateQueryBuilder.ts:403:27
at Array.forEach (<anonymous>)
at UpdateQueryBuilder.createUpdateExpression (.../src/query-builder/UpdateQueryBuilder.ts:398:68)
at UpdateQueryBuilder.getQuery (.../src/query-builder/UpdateQueryBuilder.ts:50:24)
Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:9
Top Results From Across the Web
Chapter 2. Mapping Entities - Red Hat on GitHub
The class Flight is mapped to the Flight table, using the column id as its primary ... In plain Java APIs, the temporal...
Read more >DataAnnotations - NotMapped Attribute in EF 6 & EF Core
The NotMapped attribute can be applied to properties of an entity class for which we do not want to create corresponding columns in...
Read more >java - JPA Query selecting only specific columns without using ...
Another way is to wrap the selected properties in a custom object and execute it in a TypedQuery: String query = "SELECT NEW...
Read more >Best Practices and Common Pitfalls of Using JPA (Hibernate ...
1. The entity class must have a no-arg constructor. The entity class may have other constructors as well. The no-arg constructor must be...
Read more >Computed Properties and Entity Framework - Dave Glick
These properties work fine once you've obtained the entities and want to work with them. The problems start when you want to use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hehe…nice hack 😄
I’ll give it a go…buuuut it would be nicer to be fixed … even with a @NotColumn() decorator or smth like that 😄
Any updates? Deleting the field is a nice hack, but it may affect the code once the property will no longer exists in the object.
The idea @cstapetrei of @NotCollumn() decorator seems pretty good