aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorYasyf Mohamedali <yasyfm@gmail.com>2015-03-02 17:18:35 -0500
committerYasyf Mohamedali <yasyfm@gmail.com>2015-03-02 17:18:35 -0500
commit524238139025ccddfa886bcfd7a1a6434954e305 (patch)
tree9de6a3a023bc0975725ebb9e080d029f3400614d /activerecord/test/models
parent90387e3e6ddc87029ba1e862f87e4f27623bf360 (diff)
downloadrails-524238139025ccddfa886bcfd7a1a6434954e305.tar.gz
rails-524238139025ccddfa886bcfd7a1a6434954e305.tar.bz2
rails-524238139025ccddfa886bcfd7a1a6434954e305.zip
Honour the order of the joining model in a `has_many :through`
association when eager loading. Previously, eager loading a `has_many :through` association with no defined order would return the records in the natural order of the database. Now, these records will be returned in the order that the joining record is returned, in case there is a defined order there.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/tag.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/models/tag.rb b/activerecord/test/models/tag.rb
index 80d4725f7e..b48b9a2155 100644
--- a/activerecord/test/models/tag.rb
+++ b/activerecord/test/models/tag.rb
@@ -5,3 +5,9 @@ class Tag < ActiveRecord::Base
has_many :tagged_posts, :through => :taggings, :source => 'taggable', :source_type => 'Post'
end
+
+class OrderedTag < Tag
+ self.table_name = "tags"
+
+ has_many :taggings, -> { order('taggings.id DESC') }, foreign_key: 'tag_id'
+end