Skip to content

Instantly share code, notes, and snippets.

@ridiculous
Last active August 29, 2015 14:13
Show Gist options
  • Save ridiculous/ef620e93448e653d05dc to your computer and use it in GitHub Desktop.
Save ridiculous/ef620e93448e653d05dc to your computer and use it in GitHub Desktop.
class Merchant
include Cequel::Record
key :user_id, :int
key :source, :text
key :source_id, :text
column :name, :text
# @example
# Merchant.by_key(user_id = 1, source = 'facebook', source_id = '4213578641d')
def self.by_key(*args)
where(key_column_names.each_with_object({}) { |key, obj| obj[key] = args.shift if args.any? })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment