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

Mongoid autobuild always creating new instance

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

      In my User model I have the following embedded relation:

      embeds_one :test, autobuild: true

      When I create a new instance of User, test is uninitialized (nil), so autobuild feature returns a new instance of Test class. So far so good. But when I've started using it, I've noticed it doesn't remember the 'state'.

      For example, this doesn't work:

      user = User.new
      user.test.something = 1
      puts user.test.something

      This will print nil. Each time user.test is called, Mongoid will create a new instance of Test class.
      My expectations were different - I thought it would create only one new instance and then return that instance in following calls.
      Is this a bug or are my expectations wrong?

            Assignee:
            Unassigned Unassigned
            Reporter:
            knovoselic knovoselic
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: