-
Notifications
You must be signed in to change notification settings - Fork 285
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
Changes in sequelize to avoid calling model function overrides break alias-inference logic #1190
Comments
This change has been reverted in v6 but it's still landing in v7 |
Typing needs to be updated for more than just this situation. Hopefully we get an update soon! |
What do you mean? The change has already been reverted |
I must be speaking of a different issue, since this simple example is broken with sequelize >= 6.14. I was generalizing that there were updates that changing the typing of sequelize itself. async create(user: UserDto): Promise<User> {
return this.userRepository.create<User>(user);
} |
Can you post the TS error you're having? |
@ephys The typing got more strict, so the class definition I had was no longer "valid". export class User extends Model<User> has to be export class User extends Model<User, Partial<User>> or something like export class User extends Model<User, UserCreationDto> Sorry for hijacking this issue, since it is definitely unrelated. |
@kamronbatman very late with my reply but yes, we're changing how models are typed. This is a change from upstream Sequelize. I would recommend looking at our new They should be compatible with sequelize-typescript |
I'm not sure my issue is the same as this one, but at least it may be related. When I define a relation like this (following the readme): @Table({ tableName: 'classCategories' })
export default class ClassCategory extends BaseModel<ClassCategoryAttributes, ClassCategoryCreateAttributes> {
@Column(DataType.STRING)
declare name: string;
@Column(DataType.STRING)
declare tag: string;
@HasMany(() => ClassSubcategory)
declare classSubcategories: ClassSubcategory[];
}
@Table({ tableName: 'classSubcategories' })
export default class ClassSubcategory extends BaseModel<ClassSubcategoryAttributes, ClassSubcategoryCreateAttributes> {
@Column(DataType.STRING)
declare name: string;
@Column(DataType.STRING)
declare tag: string;
@ForeignKey(() => ClassCategory)
@Column(DataType.UUID)
declare classCategoryId: string;
@BelongsTo(() => ClassCategory)
declare classCategory: ClassCategory;
} And try to create an instance, I get the following error:
Though no alias is defined. Is it a bug, or is there something wrong with my code? |
I believe sequelize/sequelize@b253d8e breaks the alias-inference logic in
sequelize-typescript
. I believe this is because this change breaks the proxy behavior thatsequelize-typescript
relies on.I have opened an issue with
sequelize
as well: sequelize/sequelize#14003Issue
Versions
Issue type
Actual behavior
I have defined no alias in my decorators. My model
x
simply belongs toy
:GeneralError: x is associated to y using an alias. You must use the 'as' keyword to specify the alias within your include statement.
Expected behavior
Alias inference works.
Related code
https://github.com/RobinBuschmann/sequelize-typescript/blob/b60c011be2e971e56cb783d4ade994965faab916/src/model/model/model.ts#L209
The text was updated successfully, but these errors were encountered: