sdepold/sequelize — Issue #104: Many to many relationships problem
Author: LaurentZuijdwijk
Created: 2011-10-25 10:21:06+00:00
State: open

Hi,

I am encountering a problem with many to many relationships. If we have for example the following:

var Media = sequelize.import(__dirname +'/models/media');
var Project = sequelize.import(__dirname +'/models/subChapter');
Project.hasMany(Media);
Media.hasMany(Project);

Then a table called MediaProjects will be created.

When I want to add a Media object to my project, it will read out every Media object, delete them all and then add them back to the database, including the new one. I think that a single insert would begood enough...?

Could you please look into this? This performance penalty is just too great when this happens.

I noticed that this table will have primary keys defined for MediaId and for ProjectId. Why is this?

keep up the good work.

Cheers,
Laurent