Closed aylesm closed 6 years ago
Further to this, I just tried this on a default collection:
Implicit ordering; works:
[1] pry(main)> Parse::Query.new("_Installation").order(:updated_at) => #<Parse::Query:0x007fb3461819a0 @cache=true, @count=0, @includes=[], @keys=[], @limit=nil, @order=[asc(:updatedAt)], @results=nil, @skip=0, @table="_Installation", @use_master_key=true, @where=[]>
Explicit ordering; @order is empty:
[2] pry(main)> Parse::Query.new("_Installation").order(:updated_at.asc) => #<Parse::Query:0x007fb3401c0fe8 @cache=true, @count=0, @includes=[], @keys=[], @limit=nil, @order=[], @results=nil, @skip=0, @table="_Installation", @use_master_key=true, @where=[]>
Actually, this is caused by a clash with another gem in my case:
[1] pry(main)> :thing.method(:desc).source_location => [".../.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/origin-2.3.1/lib/origin/extensions/symbol.rb", 49]
Any idea of a neat work-around? The best I've come up with is this sort of thing:
Installation.all(order: Parse::Order.new(:created_at, :desc))
As of 1.7.2 (which I'm testing out), I get these results:
Parse::Query.new("_Installation").order(:updated_at).compile
# => {:order=>"updatedAt"}
Parse::Query.new("_Installation").order(:updated_at.desc).compile
# => {:order=>"-updatedAt"}
Parse::Query.new("_Installation").order(:updated_at.asc).compile
# => {:order=>"updatedAt"}
Clearly, you might have something where parse-stack is clashing with the origin
gem. Will take me some time to look at this. Another proposal would be to do (which provides the same result):
Parse::Query.new("_Installation").order('-updatedAt').compile
Parse::Query.new("_Installation").append(:order => '-updatedAt').compile
Installation.query(:order => '-updatedAt').compile
# All should produce the same query constraint:
{:order=>'-updatedAt'}
I'm closing this as the current workarounds for the conflicting methods should suffice (see answer above). You can directly set the ordering without having to call the helper desc
method, which is being overwritten by the origin
gem. This is better than adding additional methods or symbol queries.
# Set descending order of the `updatedAt` remote column/field name.
Parse::Query.new("_Installation").append(:order => '-updatedAt').compile
Installation.query(:order => '-updatedAt').compile
Hi,
I'm trying to order results by descending timestamp. Which doesn't appear to work.
My collection is called UserDailyPoints with a user_id column for Parse::User object. A column timestamp which is a Date object. This works: query = UserDailyPoints.where({ user_id: @user, order: :timestamp }) This doesn't query = UserDailyPoints.where({ user_id: @user, order: :timestamp.desc }
Please help.
Thanks.