Closed Yuma-Nagaoka closed 1 year ago
This is much needed - mutating the original object is really unexpected. See also #257 and #265.
@Yuma-Nagaoka Please add a test that sorts by order([])
. Think this will return an empty array.
@flavorjones I feel like the other implementation is closer to active record, where it does a dup
and all methods seem to modify the value in place (i.e.: are bang methods). But you are right. this is simpler.
This looks good. Just want that one test to make sure it is not breaking things if args is empty.
Also, not sure how the original code worked with 2 arguments for sorting order(:id, :name)
. In other implementations I always have had to map the args and compare those arrays (worrying about nils sneaking in). This existing solution looks like it is too simple.
Yea, ok. so my thoughts were right the order(nil)
and order({})
return []
Also, it looks like it screwed up the original order as well. These 2 tests are returning US
instead of Canada
:
Thank you for helping us with this solution. Going with #268 instead
Overview
fix #193
ActiveHash::Relation#find
can't return a correct record after executing#order
. The reason is that the#order_by_args!
method destructively reorders the 'relation' itself, and#find
is based on the 'relation's index' which has the wrong reordered index.How?
Change
#order_by_args!
method to be non-destructive.