Home > Back-end >  Why does Sequelize pluralize 'media' to medium
Why does Sequelize pluralize 'media' to medium

Time:10-21

I'm having a really big issue with sequelize trying to give me its best guess at what it thinks my table name is.

I have 3 tables. Properties, Media and a junction table PropertyMedia

For some reason when I do a join query with sequelize it gives me the error

error: column Properties->PropertyMedia.medium_id does not exist

I have done a global search to make sure that I don't have the word medium anywhere and I don't

let Media = sequelize.define('Media', {
    url: DataTypes.STRING,
    isVideo: DataTypes.BOOLEAN
}, { freezeTableName: true, tableName: 'media' });

let PropertyMedia = sequelize.define('PropertyMedia', {
    propertyId: DataTypes.INTEGER,
    mediaId: DataTypes.INTEGER
}, { freezeTableName: true, tableName: 'property_media' });

CodePudding user response:

It doesn't pluralize to "medium", it singularizes to "medium".

That is because "media" is the plural of "medium" and by default table names use the plural and references use the singular, just like you'd have user_id (singular) reference users (plural), so here medium_id (not media_id) is expected to reference media.

It's true that nowadays in English another (usually) uncountable noun "media" emerged from that (probably1 from people forgetting that it does originate from the Latin word medium in plural), but that's a special case Sequelize doesn't know about, really, and also it couldn't discern which of the two nouns you meant.

For this reason, Sequelize has ways to override the singular/plural forms.


1: I'm not an etymologist so please take this with a grain of salt.

  • Related