提交 45d0d18b 编写于 作者: J Jon Leighton 提交者: Aaron Patterson

Not really worth having the HasAssociation module for just a single method

上级 770e6893
......@@ -120,7 +120,6 @@ module Associations # :nodoc:
# So there is no need to eager load them.
autoload :AssociationCollection, 'active_record/associations/association_collection'
autoload :AssociationProxy, 'active_record/associations/association_proxy'
autoload :HasAssociation, 'active_record/associations/has_association'
autoload :ThroughAssociation, 'active_record/associations/through_association'
autoload :BelongsToAssociation, 'active_record/associations/belongs_to_association'
autoload :BelongsToPolymorphicAssociation, 'active_record/associations/belongs_to_polymorphic_association'
......
......@@ -18,8 +18,6 @@ module Associations
# If you need to work on all current children, new and existing records,
# +load_target+ and the +loaded+ flag are your friends.
class AssociationCollection < AssociationProxy #:nodoc:
include HasAssociation
delegate :group, :order, :limit, :joins, :where, :preload, :eager_load, :includes, :from, :lock, :readonly, :having, :to => :scoped
def select(select = nil)
......
......@@ -9,11 +9,11 @@ module Associations
# AssociationProxy
# BelongsToAssociation
# BelongsToPolymorphicAssociation
# AssociationCollection + HasAssociation
# AssociationCollection
# HasAndBelongsToManyAssociation
# HasManyAssociation
# HasManyThroughAssociation + ThroughAssociation
# HasOneAssociation + HasAssociation
# HasOneAssociation
# HasOneThroughAssociation + ThroughAssociation
#
# Association proxies in Active Record are middlemen between the object that
......@@ -252,6 +252,13 @@ def construct_owner_conditions(table = aliased_table, reflection = @reflection)
table.create_and(conditions)
end
# Sets the owner attributes on the given record
def set_owner_attributes(record)
if @owner.persisted?
construct_owner_attributes.each { |key, value| record[key] = value }
end
end
private
# Forwards any missing method call to the \target.
def method_missing(method, *args)
......
module ActiveRecord
module Associations
# Included in all has_* associations (i.e. everything except belongs_to)
module HasAssociation #:nodoc:
protected
# Sets the owner attributes on the given record
def set_owner_attributes(record)
if @owner.persisted?
construct_owner_attributes.each { |key, value| record[key] = value }
end
end
end
end
end
......@@ -2,8 +2,6 @@ module ActiveRecord
# = Active Record Belongs To Has One Association
module Associations
class HasOneAssociation < AssociationProxy #:nodoc:
include HasAssociation
def create(attrs = {})
new_record do |reflection|
attrs = merge_with_conditions(attrs)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册