You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I do comment.setTags(tags). It doesn't use the scope to check if the comment already have the tag before insert it again, I mean, uses the next query:
SELECT "taggable_id", "tag_id", "taggable", "created_at", "updated_at" FROM "item_tag" AS "ItemTag" WHERE "ItemTag"."taggable_id" = 1;
It should be:
SELECT "taggable_id", "tag_id", "taggable", "created_at", "updated_at" FROM "item_tag" AS "ItemTag" WHERE "ItemTag"."taggable_id" = 1 AND "ItemTag"."taggable" = 'comment';
Yes, the problem exists when use setAssociations, I checked the code and I saw when they do the select, only include the primaryKey in the where statement.
Activity
elasticsearcher commentedon Jan 27, 2017
I have a similar issue when creating a Post with its tags:
The query that creates the ItemTag row does not pass the
taggablefield:Here are my model definitions:
elasticsearcher commentedon Jan 27, 2017
I can confirm @pola88's issue using my model definitions. The
SELECTworks correctly when using theaddTagmethod, but not when usingsetTags.The above outputs:
Note how the
SELECTincludes thetaggablefield in theWHEREclause.However, the following code produces the same select but without the
taggablefield:pola88 commentedon Jan 27, 2017
Yes, the problem exists when use
setAssociations, I checked the code and I saw when they do theselect, only include theprimaryKeyin thewherestatement.https://github.com/sequelize/sequelize/blob/master/lib/associations/belongs-to-many.js#L585