-
-
Save whatcould/5a7c6c28e757544744e4 to your computer and use it in GitHub Desktop.
MySQL FIND_IN_SET to Postgresql...
This file contains hidden or 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
def self.order(ids) | |
# The postgresql way | |
update_all(["position = STRPOS(?, ','||id||',')", ",#{ids.join(',')},"]) | |
# the mysql way | |
# update_all(['position = FIND_IN_SET(id, ?)', ids.join(',')]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original gist had a strange {:id => ids} parameter that didn't seem necessary (and caused an error).