提交 8db190ac 编写于 作者: E Emilio Tagua 提交者: Jeremy Kemper

HasOneAssociation inherits AssociationProxy since it shares nothing with BelongsToAssociation.

[#2796 state:committed]
Signed-off-by: NJeremy Kemper <jeremy@bitsweat.net>
上级 8f7c657f
module ActiveRecord
module Associations
class HasOneAssociation < BelongsToAssociation #:nodoc:
class HasOneAssociation < AssociationProxy #:nodoc:
def initialize(owner, reflection)
super
construct_sql
......@@ -77,7 +77,7 @@ def find_target
the_target = @reflection.klass.find(:first,
:conditions => @finder_sql,
:select => @reflection.options[:select],
:order => @reflection.options[:order],
:order => @reflection.options[:order],
:include => @reflection.options[:include],
:readonly => @reflection.options[:readonly]
)
......@@ -88,7 +88,7 @@ def find_target
def construct_sql
case
when @reflection.options[:as]
@finder_sql =
@finder_sql =
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{owner_quoted_id} AND " +
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
else
......@@ -96,7 +96,7 @@ def construct_sql
end
@finder_sql << " AND (#{conditions})" if conditions
end
def construct_scope
create_scoping = {}
set_belongs_to_association_for(create_scoping)
......@@ -113,7 +113,7 @@ def new_record(replace_existing)
end
if replace_existing
replace(record, true)
replace(record, true)
else
record[@reflection.primary_key_name] = @owner.id unless @owner.new_record?
self.target = record
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册