You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
I have a model called
Post
with acreated_at
column. Based on that example, if I runposts = Post.query.order_by({ created_at: "desc" }).limit(20)
I'm getting the following error.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 listsorder_by(__tuple : NamedTuple)
as a supported overload.My dependencies and crystal version are below:
The text was updated successfully, but these errors were encountered: