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

Changeset 1510

Show
Ignore:
Timestamp:
06/25/05 11:47:37 (5 years ago)
Author:
david
Message:

Fixed Base#find to honor the documentation on how :joins work and make them consistent with Base#count #1405 [pritchie@gmail.com] Improved dynamic finder docs #1495 [laurel@gorgorg.org]

Files:

Legend:

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

    r1509 r1510  
    11*SVN* 
     2 
     3* Fixed Base#find to honor the documentation on how :joins work and make them consistent with Base#count #1405 [pritchie@gmail.com]. What used to be: 
     4 
     5    Developer.find :all, :joins => 'developers_projects', :conditions => 'id=developer_id AND project_id=1' 
     6   
     7  ...should instead be: 
     8   
     9    Developer.find( 
     10      :all,  
     11      :joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',  
     12      :conditions => 'project_id=1' 
     13    )     
    214 
    315* Fixed that validations didn't respecting custom setting for too_short, too_long messages #1437 [Marcel Molina] 
  • trunk/activerecord/lib/active_record/base.rb

    r1471 r1510  
    136136  # == Dynamic attribute-based finders 
    137137  # 
    138   # Dynamic attribute-based finders are a cleaner way of getting objects by simple queries without turning to SQL. They work by 
    139   # appending the name of an attribute to <tt>find_by_</tt>, so you get finders like <tt>Person.find_by_user_name, Payment.find_by_transaction_id</tt>. 
    140   # So instead of writing <tt>Person.find(:first, ["user_name = ?", user_name])</tt>, you just do <tt>Person.find_by_user_name(user_name)</tt>. 
     138  # Dynamic attribute-based finders are a cleaner way of getting objects by simple queries without turning to SQL. They work by  
     139  # appending the name of an attribute to <tt>find_by_</tt> or <tt>find_all_by_</tt>, so you get finders like Person.find_by_user_name, 
     140  # Person.find_all_by_last_name, Payment.find_by_transaction_id. So instead of writing  
     141  # <tt>Person.find(:first, ["user_name = ?", user_name])</tt>, you just do <tt>Person.find_by_user_name(user_name)</tt>.  
     142  # And instead of writing <tt>Person.find(:all, ["last_name = ?", last_name])</tt>, you just do <tt>Person.find_all_by_last_name(last_name)</tt>. 
    141143  #  
    142144  # It's also possible to use multiple attributes in the same find by separating them with "_and_", so you get finders like 
     
    738740        def construct_finder_sql(options) 
    739741          sql  = "SELECT * FROM #{table_name} "  
    740           sql << ", #{options[:joins]} " if options[:joins] 
     742          sql << " #{options[:joins]} " if options[:joins] 
    741743          add_conditions!(sql, options[:conditions]) 
    742744          sql << "ORDER BY #{options[:order]} " if options[:order] 
  • trunk/activerecord/test/finder_test.rb

    r1471 r1510  
    293293 
    294294  def test_find_all_with_join 
    295     developers_on_project_one = Developer.find :all, :joins => 'developers_projects', :conditions => 'id=developer_id AND project_id=1' 
    296  
     295    developers_on_project_one = Developer.find( 
     296      :all,  
     297      :joins => 'LEFT JOIN developers_projects ON developers.id = developers_projects.developer_id',  
     298      :conditions => 'project_id=1' 
     299    ) 
    297300    assert_equal 2, developers_on_project_one.length 
    298301    developer_names = developers_on_project_one.map { |d| d.name }