Last active
December 10, 2019 07:20
-
-
Save dapi/63a7adafeb28431d5649 to your computer and use it in GitHub Desktop.
Ordered find record by intarray in Postgresql with Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find ordered record for postgresql in Rails | |
# enable_extension "intarray" | |
module FindOrdered | |
extend ActiveSupport::Concern | |
included do | |
scope :find_ordered, ->(ids) { where(id: ids).order("idx(ARRAY#{ids}::integer[], id)") } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment