Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed major bug in Tag.with_type_scope
Because we are doing a lot of joins and selecting all columns, ActiveRecord was using the ID from one of the other tables in some cases (at least on SQLite). You can see that in the example below it is using the ID from Tagging. e.g. (before fix then after) SQL $ script/dbconsole sqlite> SELECT distinct * FROM "tags" left outer join taggings on taggings.tag_id = tags.id WHERE ("tags"."id" = 4) AND (taggable_type = 'Message') GROUP BY name ORDER BY name ASC; 4|wtf|1|5|4|9|Message| sqlite> SELECT distinct tags.* FROM "tags" left outer join taggings on taggings.tag_id = tags.id WHERE ("tags"."id" = 4) AND (taggable_type = 'Message') GROUP BY name ORDER BY name ASC; 4|wtf|1 ActiveRecord $ script/console >> # BEFORE >> Tag.with_type_scope('Comment') do ?> Tag.find(4) >> end => #<Tag id: 5, name: "wtf", taggings_count: 1> >> ?> #AFTER >> Tag.with_type_scope('Comment') do ?> Tag.find(4) >> end => #<Tag id: 4, name: "wtf", taggings_count: 1> >> Tagging.find(5) => #<Tagging id: 5, tag_id: 4, taggable_id: 9, taggable_type: "Message", user_id: nil> Signed-off-by: Wesley Beary <me@geemus.com>
- Loading branch information