lib/dato/local/items_repo.rb in dato-0.6.16 vs lib/dato/local/items_repo.rb in dato-0.6.17
- old
+ new
@@ -132,14 +132,19 @@
end
item_types.each do |item_type|
method = item_type_methods[item_type]
if !item_type.singleton && item_type.sortable
- @collections_by_type[method].sort_by!(&:position)
+ nil_items, valid_items = @collections_by_type[method].partition do |item|
+ item.position.nil?
+ end
+ @collections_by_type[method] = valid_items.sort_by(&:position) + nil_items
elsif item_type.ordering_field
- @collections_by_type[method].sort_by! do |item|
- item[item_type.ordering_field.api_key]
+ field = item_type.ordering_field.api_key
+ nil_items, valid_items = @collections_by_type[method].partition do |item|
+ item[field].nil?
end
+ @collections_by_type[method] = valid_items.sort_by { |item| item[field] } + nil_items
if item_type.ordering_direction == 'desc'
@collections_by_type[method].reverse!
end
end
end