Arrays in Sequelize with Postgres

2,284 views
Skip to first unread message

Joao Barbosa

unread,
Jul 25, 2013, 6:46:56 AM7/25/13
to sequ...@googlegroups.com

Hi,

sorry if this doubts were already asked but i didn't found anything about it.

How can i insert arrays to a column that is an array in a postgres db throught sequelize?

How can i make querys to arrays?

Performance wise, arrays are viable or is better to use a string field instead?

Thank you

Joao Barbosa

unread,
Jul 25, 2013, 1:14:15 PM7/25/13
to sequ...@googlegroups.com
The first question i have already found out.

A new question come to mind, which is, how it works the manipulation of an array foreign key (add and update)?

Thank you

Joao Barbosa

unread,
Jul 30, 2013, 6:34:22 AM7/30/13
to sequ...@googlegroups.com
Anyone?

Joao Barbosa

unread,
Jul 31, 2013, 4:34:51 AM7/31/13
to sequ...@googlegroups.com
Sure =)

Project = Sequelize.define("Project",{...});
Users = Sequelize.define("Users",{project: Sequelize.ARRAY(Sequelize.STRING)});

Project.hasMany(Users,{foreignKey: project);

objUser = Users.create(...);


From some tests of mine, if you do Project.addUsers(objUser) it will ask you for an array. How can i do this?
The performance is good if you work with arrays as foreign keys? Are there methods for arrays as foreign keys?

Thank you

Daniel Durante

unread,
Jul 31, 2013, 7:46:54 PM7/31/13
to sequ...@googlegroups.com
Ah sorry dude, I didn't understand your second question correctly, as of right now Sequelize has no way of supporting multiple foreign keys, this is something that we'll be tackling sooner rather than later though.

Joao Barbosa

unread,
Aug 1, 2013, 5:54:57 AM8/1/13
to sequ...@googlegroups.com
Is the performance of Sequelize operations good if you are working with arrays as foreign keys?

Anyway seems like it is something that needs work, so for now i will find another solution.

Have another question if you don't mind...How can i delete a reference of an association table?

Thank you

Joao Barbosa

unread,
Aug 2, 2013, 12:40:01 PM8/2/13
to sequ...@googlegroups.com
Anyone can help?

Daniel Durante

unread,
Aug 2, 2013, 7:45:12 PM8/2/13
to sequ...@googlegroups.com
model.remove<AssociationName>()

For more details/examples:


I can't really be explicit without knowing your model names ad how they're associated.

Joao Barbosa

unread,
Aug 12, 2013, 6:42:00 AM8/12/13
to sequ...@googlegroups.com
Thank you for the help. Don't know why but it didn't worked before.
Reply all
Reply to author
Forward
0 new messages