Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Bug: Rails 4 order hashes fail inside a has_many. #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,15 @@ module ActiveRecord
end
end

it 'allows AR 4.0-style hash options inside an association' do
if activerecord_version_at_least '4.0.0'
block = Person.first.articles_with_order
block.to_sql.should match /ORDER BY "articles"\."title" DESC/
else
pending 'Not required in AR versions < 4.0.0'
end
end

it 'allows ordering by an attributes of a joined table' do
relation = Article.joins(:person).order { person.id.asc }
relation.to_sql.should match /ORDER BY "people"\."id" ASC/
Expand Down
2 changes: 2 additions & 0 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Person < ActiveRecord::Base
has_many :article_comments_with_first_post,
lambda { where :body => 'first post' },
:through => :articles, :source => :comments
has_many :articles_with_order, lambda { order :title => :desc },
:class_name => 'Article'
else
has_many :articles_with_condition, :conditions => {:title => 'Condition'},
:class_name => 'Article'
Expand Down