include Sequelize.col s.replace is not a function

See original GitHub issue

Issue Description

What are you doing?

I get an exception when querying data through the association table and combining fields. For example, collections is the main table, collection_products is the associated table, and products is the associated word table. The query statement is as follows:

await model.collections.findOne({
            include: [
                'images',
                {
                    model: model.collection_products,
                    as: 'products',
                    attributes: ['id', Sequelize.sequelize.col('product.title')],
                    include: {
                        model: model.products,
                        as: 'product'
                    }
                }
            ],
            where: {
                handle: this.ctx.params.handle
            }
        })

What do you expect to happen?

输出结果

{
    "id": "9259e355-b30e-47ab-9da6-6289c65b98b0",
    "title": "Photo Engraved Necklaces",
    "images": [
        {
            "id": "e4b4ebda-726c-42dc-868d-fc2984f8b4bc",
        }
    ],
    "products": [
        {
            "id": "4b750c88-ddaa-4605-9f5c-318011651d25",
			"title": "Engraved Double Heart Birthstone Promise Ring Silver",
			"handle": "engraved-double-heart-birthstone-promise-ring-silver",
        },
        {
            "id": "adb04f9e-d35a-49d1-a6b3-ef879a62663d",
			"title": "I Love You Bracelet In 100 Languages Projection Engraved Bracelet Four",
			"handle": "i-love-you-bracelet-in-100-languages-projection-engraved-bracelet-four",
        }
    ]
}

What is actually happening?

An error message was output

s.replace is not a function

Additional context

image

Environment

  • Sequelize version: 5.21.12
  • Node.js version: v13.12.0
  • Operating System: windows 10

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don’t know how to start, I would need guidance.
  • No, I don’t have the time, although I believe I could do it if I had the time…
  • No, I don’t have the time and I wouldn’t even know how to start.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
satishakumar-simpplrcommented, Apr 7, 2022

Getting this error while doing bulk insert

Model.bulkCreate(listRecordToInsert, {updateOnDuplicate: ['id']}).catch((error) => {
                if(error){
                    console.log(error);
                }
            });
TypeError: s.replace is not a function
    at Object.removeTicks (service\node_modules\sequelize\lib\utils.js:281:12)
    at PostgresQueryGenerator.quoteIdentifier [as _quoteIdentifier] (service\node_modules\sequelize\lib\dialects\postgres\query-generator.js:656:33)
    at PostgresQueryGenerator.quoteIdentifier (service\node_modules\sequelize\lib\dialects\abstract\query-generator.js:645:19)
    at service\node_modules\sequelize\lib\dialects\abstract\query-generator.js:239:68
    at Array.map (<anonymous>)
    at PostgresQueryGenerator.bulkInsertQuery (service\node_modules\sequelize\lib\dialects\abstract\query-generator.js:239:49)
    at PostgresQueryInterface.bulkInsert (service\node_modules\sequelize\lib\dialects\abstract\query-interface.js:335:68)
    at recursiveBulkCreate (service\node_modules\sequelize\lib\model.js:1657:52)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Function.bulkCreate (service\node_modules\sequelize\lib\model.js:1746:12)
0reactions
mhugginscommented, Jun 11, 2022

I’m running into this error when I use a calculated index field in conjunction with upsert on a Postgres database.

Report.init(
  {
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true
    },
    userId: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    createdAt: DataTypes.DATE,
    updatedAt: DataTypes.DATE,
  },
  {
    sequelize,
    tableName: 'reports',
    indexes: [
      {
        name: 'idx_managed_report',
        fields: [sequelize.literal('("userId" is null)'), 'name'], // this line here
        unique: true,
        where: { userId: null },
      },
    },
  },
);

await Report.upsert({ name: 'All Data' });
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: s.replace is not a function - Stack Overflow
And to anybody getting s.replace error it is basically because you are not passing the expected type of argument. So in above case, ......
Read more >
[Solved]-TypeError: s.replace is not a function-sequelize.js
And to anybody getting s.replace error it is basically because you are not passing the expected type of argument. So in above case,...
Read more >
TypeError: replace is not a function in JavaScript | bobbyhadz
The "replace is not a function" error occurs when we call the replace() method on a value that is not of type string...
Read more >
How to solve the "is not a function" error in JavaScript
We are not required to add them. Sometimes, however, we must pay attention. In particular, in Node.js we use require() to load external...
Read more >
Upgrade to v6 - Sequelize
Option returning: true will no longer return attributes that are not defined in the model. Old behavior can be achieved by using returning: ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found