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(<<-SQL, *params.values)
  SELECT
    *
  FROM
    #{self.table_name}
  WHERE
    #{where_line}
SQL
  results.map { |attrs| self.new(attrs) }
end