Module: RailzLite::Searchable

Included in:
SQLObject
Defined in:
lib/railz_lite/models/searchable.rb

Instance Method Summary collapse

Instance Method Details

#where(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/railz_lite/models/searchable.rb', line 5

def where(params)
  where_line = params.keys.map { |attr_name| "#{attr_name} = ?" }.join(" AND ")
  results = DBConnection.execute("  SELECT\n    *\n  FROM\n    \#{self.table_name}\n  WHERE\n    \#{where_line}\n", *params.values)
  results.map { |attrs| self.new(attrs) }
end