镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

M:N Associations - Comment in sample is wrong #567

Open

Description

@i-g-k

Issue Description

Minor error on docs/v6/advanced-assoc/advanced-many-many

What was unclear/insufficient/not covered in the documentation

// structure has the form `user.grants[].profiles[]`.

is not truthful.

If possible: Provide some suggestion on how we can enhance the docs

user.grants[].profiles[] should be user.grants[].profile

Additional context

Super simple repro:

async function main() {
  let sequelize = require("sequelize");
  const { DataTypes } = sequelize;

  sequelize = new sequelize({ dialect: "sqlite", logging: false });

  const User = sequelize.define(
    "user",
    {
      username: DataTypes.STRING,
      points: DataTypes.INTEGER,
    },
    { timestamps: false }
  );

  const Profile = sequelize.define(
    "profile",
    {
      name: DataTypes.STRING,
    },
    { timestamps: false }
  );

  const Grant = sequelize.define(
    "grant",
    {
      id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false,
      },
      selfGranted: DataTypes.BOOLEAN,
    },
    { timestamps: false }
  );

  User.hasMany(Grant);
  Grant.belongsTo(User);

  Profile.hasMany(Grant);
  Grant.belongsTo(Profile);

  await sequelize.sync();

  // ---

  const amidala = await User.create(
    {
      username: "p4dm3",
      points: 1000,
      grants: [
        {
          selfGranted: true,

          profile: {
            name: "Queen",
          },
        },
      ],
    },
    {
      include: {
        model: Grant,
        include: Profile,
      },
    }
  );

  const result = await User.findOne({
    where: { username: "p4dm3" },
    include: {
      model: Grant,
      include: Profile,
    },
  });

  console.dir(result.grants, { depth: 1 });
}

main();

Activity

  1. i-g-k commented on Aug 27, 2023

    @i-g-k
    Author

    See #568

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions