New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ordering issue with has_many and "nulls last" #11571
Comments
Confirm for 4.0.0, 3.2.13 and for master: unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
#gem 'rails', path: '../rails'
#gem 'rails', '= 3.2.13'
gem 'rails', '= 4.0.0'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :items do |t|
t.string 'type'
end
end
class Item < ActiveRecord::Base
default_scope { order 'type ASC nulls last' }
end
class BugTest < MiniTest::Unit::TestCase
def test_association_stuff
assert_includes Item.last.to_sql, 'ORDER BY type DESC nulls last LIMIT 1'
end
end Investigating in resolving the issue. |
Order part of query with custom statements like `nulls first` or `nulls last` at the end which arrange `null` values to top or bottom, is broken for reverse order sql generation by adding `DESC` at the end, because of skipping `asc|desc` before `nulls first|last` expression. Refactored `reverse_sql_order` to take in account, that there is `nulls` statement after order direction which are supported by ANSI from 2008. Closes rails#11571
Order part of query with custom statements like `nulls first` or `nulls last` at the end which arrange `null` values to top or bottom, is broken for reverse order sql generation by adding `DESC` at the end, because of skipping `asc|desc` before `nulls first|last` expression. Refactored `reverse_sql_order` to take in account, that there is `nulls` statement after order direction which are supported by ANSI from 2008. Closes rails#11571
Hi, any updates on this one? |
There is PR for this issue: #7423 |
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the Thank you for all your contributions. |
Just removed the stale tag since it still an issue and it has a PR: #7423 |
We'v rejected the PRs for this issue, so I'm closing this as wontfix. |
Using Rails 4 and Postgres. Invalid sql is generated with a custom has_many order clause when accessing
.last
The text was updated successfully, but these errors were encountered: