lib/mobility/backends/sequel/query_methods.rb in mobility-0.4.1 vs lib/mobility/backends/sequel/query_methods.rb in mobility-0.4.2

- old
+ new

@@ -11,9 +11,15 @@ =end class QueryMethods < Module # @param [Array<String>] attributes Translated attributes def initialize(attributes, _) @attributes = attributes.map!(&:to_sym) + + attributes.each do |attribute| + define_method :"first_by_#{attribute}" do |value| + where(attribute.to_sym => value).select_all(model.table_name).first + end + end end def extract_attributes(cond) cond.is_a?(Hash) && Util.presence(cond.keys & @attributes) end