Method: ActiveRecord::Base.find_all
- Defined in:
- lib/active_record/base.rb
.find_all(conditions = nil, orderings = nil, limit = nil, joins = nil) ⇒ Object
Returns an array of all the objects that could be instantiated from the associated table in the database. The conditions
can be used to narrow the selection of objects (WHERE-part), such as by “color = ‘red’”, and arrangement of the selection can be done through orderings
(ORDER BY-part), such as by “last_name, first_name DESC”. A maximum of returned objects and their offset can be specified in limit
(LIMIT…OFFSET-part). Examples:
Project.find_all "category = 'accounts'", "last_accessed DESC", 15
Project.find_all ["category = ?", category_name], "created ASC", ["? OFFSET ?", 15, 20]
345 346 347 348 349 350 351 352 353 354 |
# File 'lib/active_record/base.rb', line 345 def find_all(conditions = nil, orderings = nil, limit = nil, joins = nil) sql = "SELECT * FROM #{table_name} " sql << "#{joins} " if joins add_conditions!(sql, conditions) sql << "ORDER BY #{orderings} " unless orderings.nil? connection.add_limit!(sql, sanitize_sql(limit)) unless limit.nil? find_by_sql(sql) end |