diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-03 10:52:05 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-03 10:52:05 +0000 |
commit | abc895b82829657d34f4902ce0cf04f0682bab63 (patch) | |
tree | df164ff14acac26c22a3205331a5ae4898f05d03 /activerecord/lib/active_record/deprecated_finders.rb | |
parent | 17e5035bc566815b8aa8c192fec97a781f726938 (diff) | |
download | rails-abc895b82829657d34f4902ce0cf04f0682bab63.tar.gz rails-abc895b82829657d34f4902ce0cf04f0682bab63.tar.bz2 rails-abc895b82829657d34f4902ce0cf04f0682bab63.zip |
Added new Base.find API and deprecated find_all, find_first. Added preliminary support for eager loading of associations
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1077 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/deprecated_finders.rb')
-rw-r--r-- | activerecord/lib/active_record/deprecated_finders.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/deprecated_finders.rb b/activerecord/lib/active_record/deprecated_finders.rb new file mode 100644 index 0000000000..cdbba37085 --- /dev/null +++ b/activerecord/lib/active_record/deprecated_finders.rb @@ -0,0 +1,41 @@ +module ActiveRecord + class Base # :nodoc: + class << self + # This method is deprecated in favor of find with the :conditions option. + # + # Works like find, but the record matching +id+ must also meet the +conditions+. + # +RecordNotFound+ is raised if no record can be found matching the +id+ or meeting the condition. + # Example: + # Person.find_on_conditions 5, "first_name LIKE '%dav%' AND last_name = 'heinemeier'" + def find_on_conditions(ids, conditions) + find(ids, :conditions => conditions) + end + + # This method is deprecated in favor of find(:first, options). + # + # Returns the object for the first record responding to the conditions in +conditions+, + # such as "group = 'master'". If more than one record is returned from the query, it's the first that'll + # be used to create the object. In such cases, it might be beneficial to also specify + # +orderings+, like "income DESC, name", to control exactly which record is to be used. Example: + # Employee.find_first "income > 50000", "income DESC, name" + def find_first(conditions = nil, orderings = nil, joins = nil) + find(:first, :conditions => conditions, :order => orderings, :joins => joins) + end + + # This method is deprecated in favor of find(:all, options). + # + # 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+ with either just a single integer as the limit or as an array with the first element as the limit, + # the second as the offset. Examples: + # Project.find_all "category = 'accounts'", "last_accessed DESC", 15 + # Project.find_all ["category = ?", category_name], "created ASC", [15, 20] + def find_all(conditions = nil, orderings = nil, limit = nil, joins = nil) + limit, offset = limit.is_a?(Array) ? limit : [ limit, nil ] + find(:all, { :conditions => conditions, :order => orderings, :joins => joins, :limit => limit, :offset => offset}) + end + end + end +end
\ No newline at end of file |