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

becomes removes associations

      If you call becomes on a document it'll remove it's associations

      For example

      class Recipe
        include Mongoid::Document
      
        field :title, type: String
      
        embeds_many :ingredients
      end
      
      class RemoteRecipe < Recipe
      
        field :source_url, type: String
      end
      
      class Ingredient
        include Mongoid::Document
      
        field :name, type: String
        field :quantity, type: String
      
        embedded_in :recipe
      end
      

      Now assume the following about recipe.

      recipe.title
      => "Chocolate Crackle Cookies" 
      recipe.class
      => RemoteRecipe
      recipe.ingredients
      => [#<Ingredient _id: 50494933aa113e7f6000001c, _type: nil, name: "Zucchini", quantity: "4 qts.">]
      

      if I then call recipe = recipe.becomes(Recipe) and now recipe is as follows

      recipe.title
      => "Chocolate Crackle Cookies" 
      recipe.class
      => Recipe
      recipe.ingredients
      => []
      

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

              Created:
              Updated:
              Resolved: