<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -759,6 +759,7 @@ module ActiveRecord
       # * &lt;tt&gt;:foreign_key&lt;/tt&gt; - Specify the foreign key used for the association. By default this is guessed to be the name
       #   of this class in lower-case and &quot;_id&quot; suffixed. So a Person class that makes a +has_one+ association will use &quot;person_id&quot;
       #   as the default &lt;tt&gt;:foreign_key&lt;/tt&gt;.
+      # * &lt;tt&gt;:primary_key&lt;/tt&gt; - Specify the method that returns the primary key used for the association. By default this is +id+.
       # * &lt;tt&gt;:include&lt;/tt&gt; - Specify second-order associations that should be eager loaded when this object is loaded.
       # * &lt;tt&gt;:as&lt;/tt&gt; - Specifies a polymorphic interface (See &lt;tt&gt;belongs_to&lt;/tt&gt;).
       # * &lt;tt&gt;:select&lt;/tt&gt; - By default, this is &lt;tt&gt;*&lt;/tt&gt; as in &lt;tt&gt;SELECT * FROM&lt;/tt&gt;, but can be changed if, for example, you want to do a join
@@ -1366,7 +1367,7 @@ module ActiveRecord
 
         def create_has_one_reflection(association_id, options)
           options.assert_valid_keys(
-            :class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly, :validate
+            :class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly, :validate, :primary_key
           )
 
           create_reflection(:has_one, association_id, options, self)</diff>
      <filename>activerecord/lib/active_record/associations.rb</filename>
    </modified>
    <modified>
      <diff>@@ -47,7 +47,16 @@ module ActiveRecord
           return (obj.nil? ? nil : self)
         end
       end
-            
+
+      protected
+        def owner_quoted_id
+          if @reflection.options[:primary_key]
+            quote_value(@owner.send(@reflection.options[:primary_key]))
+          else
+            @owner.quoted_id
+          end
+        end
+
       private
         def find_target
           @reflection.klass.find(:first, </diff>
      <filename>activerecord/lib/active_record/associations/has_one_association.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,6 +29,13 @@ class HasOneAssociationsTest &lt; ActiveRecord::TestCase
     assert_equal Firm.find(1, :include =&gt; :account_with_select).account_with_select.attributes.size, 2
   end
 
+  def test_finding_using_primary_key
+    firm = companies(:first_firm)
+    assert_equal Account.find_by_firm_id(firm.id), firm.account
+    firm.firm_id = companies(:rails_core).id
+    assert_equal accounts(:rails_core_account), firm.account_using_primary_key
+  end
+
   def test_can_marshal_has_one_association_with_nil_target
     firm = Firm.new
     assert_nothing_raised do</diff>
      <filename>activerecord/test/cases/associations/has_one_associations_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -160,9 +160,9 @@ class ReflectionTest &lt; ActiveRecord::TestCase
 
   def test_reflection_of_all_associations
     # FIXME these assertions bust a lot
-    assert_equal 22, Firm.reflect_on_all_associations.size
-    assert_equal 17, Firm.reflect_on_all_associations(:has_many).size
-    assert_equal 5, Firm.reflect_on_all_associations(:has_one).size
+    assert_equal 24, Firm.reflect_on_all_associations.size
+    assert_equal 18, Firm.reflect_on_all_associations(:has_many).size
+    assert_equal 6, Firm.reflect_on_all_associations(:has_one).size
     assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
   end
 </diff>
      <filename>activerecord/test/cases/reflection_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -53,6 +53,7 @@ class Firm &lt; Company
   has_one :unvalidated_account, :foreign_key =&gt; &quot;firm_id&quot;, :class_name =&gt; 'Account', :validate =&gt; false
   has_one :account_with_select, :foreign_key =&gt; &quot;firm_id&quot;, :select =&gt; &quot;id, firm_id&quot;, :class_name=&gt;'Account'
   has_one :readonly_account, :foreign_key =&gt; &quot;firm_id&quot;, :class_name =&gt; &quot;Account&quot;, :readonly =&gt; true
+  has_one :account_using_primary_key, :primary_key =&gt; &quot;firm_id&quot;, :class_name =&gt; &quot;Account&quot;
 end
 
 class DependentFirm &lt; Company</diff>
      <filename>activerecord/test/models/company.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>3351d2997017465047b2c3dc63dc31e2362368af</id>
    </parent>
  </parents>
  <author>
    <name>Brad Greenlee</name>
    <email>brad@wesabe.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/afa0c7f728a8896c9ee9d932033e08a4c99dfd50</url>
  <id>afa0c7f728a8896c9ee9d932033e08a4c99dfd50</id>
  <committed-date>2008-07-06T11:25:10-07:00</committed-date>
  <authored-date>2008-06-02T22:04:46-07:00</authored-date>
  <message>Add support for :primary_key option to has_one as well as has_many so that a key other than the default primary key can be used for the association

Signed-off-by: Michael Koziarski &lt;michael@koziarski.com&gt;</message>
  <tree>6fd8642f524facf4d1d2584c21ce7b8d30b9d424</tree>
  <committer>
    <name>Michael Koziarski</name>
    <email>michael@koziarski.com</email>
  </committer>
</commit>
