Sha256: b25c356f57e24c261971ebd050d82f54361d1eaada0075981da549ad63a45800
Contents?: true
Size: 735 Bytes
Versions: 2
Compression:
Stored size: 735 Bytes
Contents
# frozen_string_literal: true module Oort module Scopes def self.included(base) # user = User.find(909) # user.posts.ordered_with(user.posts_ordered) # by default this will use posts.id::INTEGER # but you can pass in something else if you have joins and items # stored in another table base.scope :ordered_with, lambda { |ids, type = "#{table_name}.id::INTEGER"| if ids.blank? order(:id) else order(Arel.sql("array_position(ARRAY[#{ids.join(", ")}], #{type})")) end } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
oort-0.2.1 | lib/oort/scopes.rb |
oort-0.2.0 | lib/oort/scopes.rb |