Skip to content
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

NamedFunction cannot be used for ordering anymore in arel 6 #399

Closed
fschwahn opened this issue Nov 6, 2015 · 3 comments
Closed

NamedFunction cannot be used for ordering anymore in arel 6 #399

fschwahn opened this issue Nov 6, 2015 · 3 comments

Comments

@fschwahn
Copy link

fschwahn commented Nov 6, 2015

Hi,
with arel 5 I could do the following:

t = Arel::Table.new(:table)
Arel::Nodes::NamedFunction.new('CAST', [t[:date].as("TIME")]).desc

Which would allow me to order according to a named function. This does not work in arel 6 anymore:

undefined method `asc' for #<Arel::Nodes::NamedFunction:0x007fc858b977d8> (NoMethodError)

Is there any reason this functionality was removed, or is this a regression?

The following can be used to reproduce:

#!/usr/bin/env ruby

begin
  require 'bundler/inline'
rescue LoadError => e
  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
  raise e
end

gemfile(true) do
  source 'https://rubygems.org'
  gem 'sqlite3'

  # Arel 6
  gem 'activerecord', '~> 4.2', require: 'active_record'
  gem 'arel', '~> 6.0'

  # Arel 5
  # gem 'activerecord', '~> 4.1', require: 'active_record'
  # gem 'arel', '~> 5.0'
end

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

t = Arel::Table.new(:table, ActiveRecord::Base)
puts Arel::Nodes::NamedFunction.new('CAST', [t[:date].as("TIME")]).desc.to_sql

All the best,
Fabian

@vipulnsward
Copy link
Member

Looks like a regression.
Arel::Expression was deprecated and removed. The desc, asc calls were being imported from Arel::OrderPredications into Arel::Expression and later to NamedFunction.

You can import OrderPredications manually though. I don't think there's a need to import in in NamedFunction right now.

@fschwahn
Copy link
Author

@vipulnsward Thank you for your answer, I manually imported Arel::OrderPredications into Arel::Nodes::NamedFunction and it works perfectly.

I'm not sure if this issue should be closed, as it seems to be a regression. Maybe documenting it somewhere would be enough?

@carsonreinke
Copy link

Fix here #381

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants