Sha256: ff5482f13a869856131d127b7906b9bfc19931acbf5c08a69eb26b2bc51868f8
Contents?: true
Size: 1.06 KB
Versions: 6
Compression:
Stored size: 1.06 KB
Contents
module Mongoid #:nodoc: module Associations #:nodoc: class HasOne #:nodoc: include Decorator delegate :valid?, :to => :document # Creates the new association by finding the attributes in # the parent document with its name, and instantiating a # new document for it. # # All method calls on this object will then be delegated # to the internal document itself. def initialize(name, document, options = {}) class_name = options[:class_name] klass = class_name ? class_name.constantize : name.to_s.camelize.constantize attributes = document.attributes[name] @document = klass.new(attributes) @document.parentize(document, name) decorate! end class << self # Perform an update of the relationship of the parent and child. This # is initialized by setting the has_one to the supplied child. def update(child, parent, name) child.parentize(parent, name) child.notify child end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems