modernistik / parse-stack

Parse Server Ruby Client SDK
https://www.modernistik.com/gems/parse-stack/
MIT License
61 stars 20 forks source link

order constraint for Date column not working. #41

Closed aylesm closed 6 years ago

aylesm commented 6 years ago

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.

GrahamW commented 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=[]>

GrahamW commented 6 years ago

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))

apersaud commented 6 years ago

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 origingem. 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'}
apersaud commented 6 years ago

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