beezwax / fmrest-ruby

FileMaker Data API client for Ruby with ActiveRecord-like ORM features
MIT License
22 stars 10 forks source link

limit(1).find_some and find_one not attaching sort params to GET #23

Closed leehericks closed 5 years ago

leehericks commented 5 years ago

I'm attempting to retrieve the latest "Term" from our FileMaker database by sorting the records by the term's end date descending and then retrieving the first record.

Doing a limit of 2 results in the sort working and the most recent two records being returned.

FileMaker::Term.sort(:fm_end_date!).limit(2).find_some

GET https://<server>/fmi/data/v1/databases/<dbname>/layouts/<layoutname>/records?_limit=2&_sort=%5B%7B%22fieldName%22%3A%22%E7%B5%82%E4%BA%86%E6%97%A5%22%2C%22sortOrder
%22%3A%22descend%22%7D%5D

But calling a limit of 1 and find_some or simply calling find_one does not attach the sort params although they exist in the Spyke Relation.

FileMaker::Term.sort(:fm_end_date!).limit(1).find_some

<FmRest::Spyke::Relation:0x00007f866817e238 @klass=FileMaker::Term, @options={:uri=>"layouts/dls_terms/records(/:id)"}, @params={}, @should_fallback=false, @limit_value=1, @query_params=[], @portal_params=[], @sort_params=[{:fieldName=>
"終了日", :sortOrder=>"descend"}]>

GET https://<server>/fmi/data/v1/databases/<dbname>/layouts/<layoutname>/records?_limit=1

I have not been able to find a place in the source code where limit(1) or find_one would be ignoring the sort params.

pilaf commented 5 years ago

Thanks for the bug report.

Indeed, it seems the sort params are being actively ignored when .limit(1) is used. Bad idea. I'll push a fix shortly.

pilaf commented 5 years ago

Just released v0.2.1 with a fix.

4e2a6fc9dd156a1702afdd48b4530759953b002f Don't ignore .sort params when .limit(1) is used 80094a815ff2c63282c9a8a7872754872ba49aa4 Bump version to 0.2.1

@leehericks Please confirm this fixes it for you if you could.

leehericks commented 5 years ago

Gem updated, tested and confirmed fixed! Thank you!