We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When i try to get a ModelA include ModelB the key of the association is undefined but in VALUE.dataValues.ASSOCIATION i've the values
undefined
VALUE.dataValues.ASSOCIATION
Example:
User Table
import { Column, HasMany, Model, Table } from "sequelize-typescript"; import { Post } from "./Post"; @Table export class User extends Model<User> { @Column({ allowNull: false, unique: true, primaryKey: true, }) declare id: number; @HasMany(() => Post, { as: "CreatedPosts" }) CreatedPosts: Post[]; }
Post Table
import { BelongsTo, Column, ForeignKey, Model, Table, } from "sequelize-typescript"; import { User } from "./User"; @Table export class Post extends Model<Post> { @Column({ allowNull: false, unique: true, primaryKey: true, }) declare id: number; @ForeignKey(() => User) @Column declare userId: number; @BelongsTo(() => User) user: User; }
Try to get user with association post
const sequelize = new Sequelize({ dialect: "sqlite", storage: "database.sqlite", logging: false, sync: { alter: true }, define: { timestamps: false, underscored: true, }, }); sequelize.addModels([Models.User, Models.Post]); sequelize.sync().then(() => { Models.User.findByPk(1, { include: [Models.Post], plain: true, }).then((user) => { console.log(user); // User Object console.log(user.CreatedPosts); // Undefined console.log(user.dataValues.CreatedPosts); // Array of User Posts }); });
return
User { dataValues: { id: 1, CreatedPosts: [ [Post] ] }, _previousDataValues: { id: 1, CreatedPosts: [ [Post] ] }, uniqno: 1, _changed: Set(0) {}, _options: { isNewRecord: false, _schema: null, _schemaDelimiter: '', include: [ [Object] ], includeNames: [ 'CreatedPosts' ], includeMap: { CreatedPosts: [Object] }, includeValidated: true, attributes: [ 'id' ], raw: true }, isNewRecord: false, CreatedPosts: undefined } undefined [ Post { dataValues: { id: 12, userId: 1 }, _previousDataValues: { id: 12, userId: 1 }, uniqno: 1, _changed: Set(0) {}, _options: { isNewRecord: false, _schema: null, _schemaDelimiter: '', include: undefined, includeNames: undefined, includeMap: undefined, includeValidated: true, raw: true, attributes: undefined }, isNewRecord: false, user: undefined } ]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Issue
When i try to get a ModelA include ModelB the key of the association is
undefined
but inVALUE.dataValues.ASSOCIATION
i've the valuesExample:
User Table
Post Table
Try to get user with association post
return
Versions
Issue type
The text was updated successfully, but these errors were encountered: