Skip to content

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

@i-g-k

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();

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