Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1867

Association not set in default value lambda through association proxy

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.8
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      class Parent
        include Mongoid::Document
        
        field :surname, :type => String
        
        has_many :children, :dependent => :destroy
      end
      
      class Child
        include Mongoid::Document
        
        belongs_to :parent
        
        field :surname, :type => String, :default => lambda { parent.surname if parent }
      end
      
      parent = Parent.create!(:surname => "Bond")
      
      p Child.new(:parent => parent).surname # "Bond" :D
      p parent.children.build.surname # nil :(
      

      The behaviour of Child.new(:parent => parent) and parent.children.build ought to be the same.

            Assignee:
            Unassigned Unassigned
            Reporter:
            dbackeus David Backeus
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: