website icon indicating copy to clipboard operation
website copied to clipboard

M:N Associations - Comment in sample is wrong

Open i-g-k opened this issue 2 years ago • 1 comments

Issue Description

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

What was unclear/insufficient/not covered in the documentation

https://github.com/sequelize/website/blob/0ebeecc2ac6866d948f5b5f496ba7cd068343a92/versioned_docs/version-6.x.x/advanced-association-concepts/advanced-many-to-many.md?plain=1#L243

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

i-g-k avatar Aug 27 '23 08:08 i-g-k

See #568

i-g-k avatar Aug 27 '23 08:08 i-g-k