Skip to content
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

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

Open
i-g-k opened this issue Aug 27, 2023 · 1 comment
Open

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

i-g-k opened this issue Aug 27, 2023 · 1 comment

Comments

@i-g-k
Copy link

i-g-k commented Aug 27, 2023

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();
@i-g-k
Copy link
Author

i-g-k commented Aug 27, 2023

See #568

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant