| 1 | module ActiveRecord |
|---|
| 2 | class Base |
|---|
| 3 | class << self |
|---|
| 4 | # This method is deprecated in favor of find with the :conditions option. |
|---|
| 5 | # |
|---|
| 6 | # Works like find, but the record matching +id+ must also meet the +conditions+. |
|---|
| 7 | # +RecordNotFound+ is raised if no record can be found matching the +id+ or meeting the condition. |
|---|
| 8 | # Example: |
|---|
| 9 | # Person.find_on_conditions 5, "first_name LIKE '%dav%' AND last_name = 'heinemeier'" |
|---|
| 10 | def find_on_conditions(ids, conditions) # :nodoc: |
|---|
| 11 | find(ids, :conditions => conditions) |
|---|
| 12 | end |
|---|
| 13 | |
|---|
| 14 | # This method is deprecated in favor of find(:first, options). |
|---|
| 15 | # |
|---|
| 16 | # Returns the object for the first record responding to the conditions in +conditions+, |
|---|
| 17 | # such as "group = 'master'". If more than one record is returned from the query, it's the first that'll |
|---|
| 18 | # be used to create the object. In such cases, it might be beneficial to also specify |
|---|
| 19 | # +orderings+, like "income DESC, name", to control exactly which record is to be used. Example: |
|---|
| 20 | # Employee.find_first "income > 50000", "income DESC, name" |
|---|
| 21 | def find_first(conditions = nil, orderings = nil, joins = nil) # :nodoc: |
|---|
| 22 | find(:first, :conditions => conditions, :order => orderings, :joins => joins) |
|---|
| 23 | end |
|---|
| 24 | |
|---|
| 25 | # This method is deprecated in favor of find(:all, options). |
|---|
| 26 | # |
|---|
| 27 | # Returns an array of all the objects that could be instantiated from the associated |
|---|
| 28 | # table in the database. The +conditions+ can be used to narrow the selection of objects (WHERE-part), |
|---|
| 29 | # such as by "color = 'red'", and arrangement of the selection can be done through +orderings+ (ORDER BY-part), |
|---|
| 30 | # such as by "last_name, first_name DESC". A maximum of returned objects and their offset can be specified in |
|---|
| 31 | # +limit+ with either just a single integer as the limit or as an array with the first element as the limit, |
|---|
| 32 | # the second as the offset. Examples: |
|---|
| 33 | # Project.find_all "category = 'accounts'", "last_accessed DESC", 15 |
|---|
| 34 | # Project.find_all ["category = ?", category_name], "created ASC", [15, 20] |
|---|
| 35 | def find_all(conditions = nil, orderings = nil, limit = nil, joins = nil) # :nodoc: |
|---|
| 36 | limit, offset = limit.is_a?(Array) ? limit : [ limit, nil ] |
|---|
| 37 | find(:all, :conditions => conditions, :order => orderings, :joins => joins, :limit => limit, :offset => offset) |
|---|
| 38 | end |
|---|
| 39 | end |
|---|
| 40 | end |
|---|
| 41 | end |
|---|