Changeset 1510
- Timestamp:
- 06/25/05 11:47:37 (5 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/base.rb (modified) (2 diffs)
- trunk/activerecord/test/finder_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r1509 r1510 1 1 *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 ) 2 14 3 15 * 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 136 136 # == Dynamic attribute-based finders 137 137 # 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>. 141 143 # 142 144 # It's also possible to use multiple attributes in the same find by separating them with "_and_", so you get finders like … … 738 740 def construct_finder_sql(options) 739 741 sql = "SELECT * FROM #{table_name} " 740 sql << " ,#{options[:joins]} " if options[:joins]742 sql << " #{options[:joins]} " if options[:joins] 741 743 add_conditions!(sql, options[:conditions]) 742 744 sql << "ORDER BY #{options[:order]} " if options[:order] trunk/activerecord/test/finder_test.rb
r1471 r1510 293 293 294 294 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 ) 297 300 assert_equal 2, developers_on_project_one.length 298 301 developer_names = developers_on_project_one.map { |d| d.name }