序列化列名/属性冲突?

发布于 2024-12-10 17:28:33 字数 1385 浏览 1 评论 0原文

我正在尝试为具有 options 列的表创建一个续集模型,但是当我尝试查询(例如查找)时出现错误:

/Users/camupod/node_modules/sequelize/lib/sequelize/model.js:17
  var defaults = this.options.hasPrimaryKeys ? {} : { id: null }
                             ^
TypeError: Cannot read property 'hasPrimaryKeys' of null
    at new <anonymous> (/Users/camupod/node_modules/sequelize/lib/sequelize/model.js:17:30)
    at [object Object].build (/Users/camupod/node_modules/sequelize/lib/sequelize/model-definition.js:140:18)
    at /Users/camupod/node_modules/sequelize/lib/sequelize/query.js:47:64
    at Array.map (native)
    at [object Object].onSuccess (/Users/camupod/node_modules/sequelize/lib/sequelize/query.js:47:22)
    at /Users/camupod/node_modules/sequelize/lib/sequelize/query.js:22:38
    at Query.<anonymous> (/Users/camupod/node_modules/mysql/lib/client.js:108:11)
    at Query.emit (events.js:61:17)
    at Query._handlePacket (/Users/camupod/node_modules/mysql/lib/query.js:51:14)
    at Client._handlePacket (/Users/camupod/node_modules/mysql/lib/client.js:312:14)

我的模型的定义:

Model.recording = sequelize.define(
    'recordings',
    {
        /* other columns... */
        options: Sequelize.TEXT
    },
    {
        timestamps: false,
        freezeTableName: true
    }
);

确实续集吗不允许 options 作为列名,还是我做错了什么?

I am trying to create a sequelize model for a table that has an options column, but I get an error when I attempt a query (like find, for example):

/Users/camupod/node_modules/sequelize/lib/sequelize/model.js:17
  var defaults = this.options.hasPrimaryKeys ? {} : { id: null }
                             ^
TypeError: Cannot read property 'hasPrimaryKeys' of null
    at new <anonymous> (/Users/camupod/node_modules/sequelize/lib/sequelize/model.js:17:30)
    at [object Object].build (/Users/camupod/node_modules/sequelize/lib/sequelize/model-definition.js:140:18)
    at /Users/camupod/node_modules/sequelize/lib/sequelize/query.js:47:64
    at Array.map (native)
    at [object Object].onSuccess (/Users/camupod/node_modules/sequelize/lib/sequelize/query.js:47:22)
    at /Users/camupod/node_modules/sequelize/lib/sequelize/query.js:22:38
    at Query.<anonymous> (/Users/camupod/node_modules/mysql/lib/client.js:108:11)
    at Query.emit (events.js:61:17)
    at Query._handlePacket (/Users/camupod/node_modules/mysql/lib/query.js:51:14)
    at Client._handlePacket (/Users/camupod/node_modules/mysql/lib/client.js:312:14)

And my model's definition:

Model.recording = sequelize.define(
    'recordings',
    {
        /* other columns... */
        options: Sequelize.TEXT
    },
    {
        timestamps: false,
        freezeTableName: true
    }
);

Does sequelize really not allow options as a column name, or am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-12-17 17:28:33

嗯,这是一个非常愚蠢的“边缘情况”。定义一个名为“options”的属性将覆盖模型的选项:D,这很糟糕:(。

这个问题刚刚得到解决,并且 bug 修复在 v1.1.3 中可用。请告诉我这是否有效。

Well, that's a pretty stupid "edgecase". Defining an attribute called "options" will overwrite the options of the model :D that sucks :(.

The issue was just fixed and the bugfix is available in v1.1.3. Please let me know if that works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文