Activity Load (1.0ms) SELECT `activities`.* FROM `activities` JOIN taggings activities_taggings_531c2fd ON activities_taggings_531c2fd.taggable_id = activities.id AND activities_taggings_531c2fd.taggable_type = 'Activity' AND activities_taggings_531c2fd.tag_id = 33 AND activities_taggings_531c2fd.context = 'skills' JOIN taggings activities_taggings_a841373 ON activities_taggings_a841373.taggable_id = activities.id AND activities_taggings_a841373.taggable_type = 'Activity' AND activities_taggings_a841373.tag_id = 37 AND activities_taggings_a841373.context = 'skills' JOIN taggings activities_taggings_531c2fd ON activities_taggings_531c2fd.taggable_id = activities.id AND activities_taggings_531c2fd.taggable_type = 'Activity' AND activities_taggings_531c2fd.tag_id = 33 AND activities_taggings_531c2fd.context = 'skills'
ActiveRecord::StatementInvalid: Mysql2::Error: Not unique table/alias: 'activities_taggings_531c2fd': SELECT `activities`.* FROM `activities` JOIN taggings activities_taggings_531c2fd ON activities_taggings_531c2fd.taggable_id = activities.id AND activities_taggings_531c2fd.taggable_type = 'Activity' AND activities_taggings_531c2fd.tag_id = 33 AND activities_taggings_531c2fd.context = 'skills' JOIN taggings activities_taggings_a841373 ON activities_taggings_a841373.taggable_id = activities.id AND activities_taggings_a841373.taggable_type = 'Activity' AND activities_taggings_a841373.tag_id = 37 AND activities_taggings_a841373.context = 'skills' JOIN taggings activities_taggings_531c2fd ON activities_taggings_531c2fd.taggable_id = activities.id AND activities_taggings_531c2fd.taggable_type = 'Activity' AND activities_taggings_531c2fd.tag_id = 33 AND activities_taggings_531c2fd.context = 'skills'
This occurs when chaining tagged_with and tagged_with the same tag again-- for ex:
Activity.tagged_with(["problem solving", "critical thinking"], on: :skills).tagged_with("problem solving", on: :skills)
The use case is when you have a list of items already filtered by a tag and you want a count of a certain tag within that filtered group. In the use case above, you have a list of activities with the skill.
The error is recent and only started happening when we upgraded to rails 4.2x
Our solution while not optimal, has been to re-grab the records with the original tagged with and then run tagged with again on it.
Just curious, did you have this when you were using match_all? I had this issue when I was using match_all: false and changing it to any: true made the issue disappear.
This occurs when chaining tagged_with and tagged_with the same tag again-- for ex:
Activity.tagged_with(["problem solving", "critical thinking"], on: :skills).tagged_with("problem solving", on: :skills)
The use case is when you have a list of items already filtered by a tag and you want a count of a certain tag within that filtered group. In the use case above, you have a list of activities with the skill.
The error is recent and only started happening when we upgraded to rails 4.2x
Our solution while not optimal, has been to re-grab the records with the original tagged with and then run tagged with again on it.