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

order_by not working as described in documentation #224

Open
dansbits opened this issue Feb 1, 2022 · 0 comments
Open

order_by not working as described in documentation #224

dansbits opened this issue Feb 1, 2022 · 0 comments

Comments

@dansbits
Copy link

dansbits commented Feb 1, 2022

Hello! I'm pretty new to Crystal and Clear so sorry if I'm missing something obvious.

The gitbook documentation gives the following example for how to order query results.

User.query.order_by(last_name: "ASC", first_name: "ASC").each do |usr|
    puts "#{usr.first_name} #{usr.last_name}"
end

I have a model called Post with a created_at column. Based on that example, if I run posts = Post.query.order_by({ created_at: "desc" }).limit(20) I'm getting the following error.

In lib/clear/src/clear/sql/query/order_by.cr:84:9

84 | order_by(k, v, nil)
       ^-------
Error: no overload matches 'Post::Collection#order_by' with types Symbol, String, Nil

Overloads are:
- Clear::SQL::Query::OrderBy#order_by(x : Array(Record))
- Clear::SQL::Query::OrderBy#order_by(__tuple : NamedTuple)
- Clear::SQL::Query::OrderBy#order_by(expression : Symbol, direction : Symbol = :asc, nulls : Symbol | ::Nil = nil)
- Clear::SQL::Query::OrderBy#order_by(expression : String, direction : Symbol = :asc, nulls : Symbol | ::Nil = nil)
- Clear::SQL::Query::OrderBy#order_by(**tuple)

Based on the proposed overloads in the error message I changed my code to posts = Post.query.order_by(:created_at, :desc).limit(20) to get a working result but I can't figure out why the original doesn't work. The error lists order_by(__tuple : NamedTuple) as a supported overload.

My dependencies and crystal version are below:

dependencies:
  kemal:
    github: kemalcr/kemal
  pg:
    github: will/crystal-pg
    version: 0.23.2
  clear:
    github: anykeyh/clear
    branch: master

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

No branches or pull requests

1 participant