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

unable to access parent when setting child attribute

      When setting child attribute via nested_attribute, we cannot access its parent. I've created a demo app to demonstrate the issue.

      class Image
        include Mongoid::Document
        embedded_in :page
      
        def bam= value
          puts 'calling bam='
          byebug
          puts "page: #{page}" # This is nil. Incorrect.
        end
      end
      
      class Page
        include Mongoid::Document
        embeds_many :images, cascade_callbacks: true
        accepts_nested_attributes_for :images
      end
      
      attributes = {
        'images_attributes' => {
          '0' => {
            'bam' => 'bam'
          }
        }
      }
      page = Page.new
      page.attributes = attributes
      
      puts 'after setting attributes'
      puts page.images.first.page
      

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            khoan khoa nguyen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: