-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
type: featureDEPRECATED: replace with the "feature" issue typeDEPRECATED: replace with the "feature" issue type
Description
What are you doing?
I am trying to add a custom datatype for CITEXT as part of an ARRAY. I search the database with case insensitive because I don't control the search terms. Is this possible to do with sequelize?
I tried this:
export default (sequelize, DataTypes) => {
class CITEXT extends DataTypes.TEXT {
constructor () {
super()
this.key = 'CITEXT'
}
}
const Model = sequelize.define('artist', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER
},
slug: {
allowNull: false,
type: 'CITEXT' // <-- here I use a custom class, this works
},
names: {
allowNull: false,
type: DataTypes.ARRAY(CITEXT) // <-- but this does not work
}
});
return Model;
};What do you expect to happen?
That I could access the ARRAY in sequelize like a normal JS array.
What is actually happening?
This is what I got in the console (which looks correct)
CREATE TABLE IF NOT EXISTS "artists" ("id" SERIAL, "slug" CITEXT NOT NULL, "names" CITEXT[] NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));But this is what I get in the JS code
sequelize.sync({ force: true }).then(() => {
return models.artist.create(
slug: 'cali-dubuque',
names: ['Cali DuBuque']
}).then(artist => {
console.log('===> artist.names', artist.get('names'))
// ===> artist.names {"Cali DuBuque"}
});
});artist.get('names') should output an array ['Cali DuBuque'] instead of a string '{"Cali DuBuque"}'
Dialect: postgres
Dialect version: 7.4.1 (node package pg)
Database version: 10.2 (psql --version)
Sequelize version: 4.34.1
Tested with latest release: yes
Metadata
Metadata
Assignees
Labels
type: featureDEPRECATED: replace with the "feature" issue typeDEPRECATED: replace with the "feature" issue type