Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 1058

Show
Ignore:
Timestamp:
04/02/05 08:29:54 (4 years ago)
Author:
david
Message:

Added a join parameter as the third argument to Base.find_first and as the second to Base.count #426, #988 [skaes@web.de]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r1047 r1058  
    11*SVN* 
    22 
    3 * Added a join parameter as the third argument to Base.find_first #426 [skaes@web.de] 
     3* Added a join parameter as the third argument to Base.find_first and as the second to Base.count #426, #988 [skaes@web.de] 
    44 
    55* Fixed bug in Base#hash method that would treat records with the same string-based id as different [Dave Thomas] 
  • trunk/activerecord/lib/active_record/base.rb

    r1047 r1058  
    453453      # Returns the number of records that meets the +conditions+. Zero is returned if no records match. Example: 
    454454      #   Product.count "sales > 1" 
    455       def count(conditions = nil) 
    456         sql  = "SELECT COUNT(*) FROM #{table_name} " 
     455      def count(conditions = nil, joins = nil) 
     456        tbl_var_name = joins  ? table_name[0,1].downcase : "" 
     457        sql  = "SELECT COUNT(*) FROM #{table_name} #{tbl_var_name} " 
     458        sql << ", #{joins} " if joins 
    457459        add_conditions!(sql, conditions) 
    458460        count_by_sql(sql)