Sha256: 0b7703d337893cd52c6f3a7f5bc068dd0a3c77328e6e236c1272b2b258642574
Contents?: true
Size: 1.5 KB
Versions: 2
Compression:
Stored size: 1.5 KB
Contents
module ActiveRecord module Associations class HasOneAssociation < BelongsToAssociation #:nodoc: def initialize(owner, association_name, association_class_name, association_class_primary_key_name, options) super construct_sql end def replace(obj, dont_save = false) load_target unless @target.nil? if dependent? && !dont_save @target.destroy unless @target.new_record? @owner.clear_association_cache else @target[@association_class_primary_key_name] = nil @target.save unless @owner.new_record? end end if obj.nil? @target = nil else raise_on_type_mismatch(obj) obj[@association_class_primary_key_name] = @owner.id unless @owner.new_record? @target = obj end @loaded = true unless @owner.new_record? or obj.nil? or dont_save return (obj.save ? self : false) else return (obj.nil? ? nil : self) end end private def find_target @association_class.find(:first, :conditions => @finder_sql, :order => @options[:order]) end def target_obsolete? false end def construct_sql @finder_sql = "#{@association_class.table_name}.#{@association_class_primary_key_name} = #{@owner.quoted_id}#{@options[:conditions] ? " AND " + @options[:conditions] : ""}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activerecord-1.10.1 | lib/active_record/associations/has_one_association.rb |
activerecord-1.10.0 | lib/active_record/associations/has_one_association.rb |