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

Mongoid saves my document when I set something in a embed relationship

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

      Hi guys...

      I have found a problem here. First of all I'll put my classes code.

      class Person
        include Mongoid::Document
      
        field :name, :type => String
        embeds_many :games
      
      end
      
      class Game
        include Mongoid::Document
      
        field :name, :type => String
        embedded_in :person
      
      end
      

      Lets go to the problem...I can create a person with games normally, as follow:

      person = Person.create :games => [Game.new(:name => "Sonic")]
      

      But when I set the array of games as empty:

      Unable to find source-code formatter for language: person. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      .games = []

      Mongoid saves this changes in my Mongodb...Like I could confirm looking into my mongodb log file:

      Unable to find source-code formatter for language: debug. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      : MONGODB x_development['people'].update({"_id"=>BSON::ObjectId('4e4536dcad4a262b9d000002')}, {"$unset"=>{"games"=>true}})

      This problem causes some troubles, for example, if I like to validate the presence of at least one game in my person object, I cant, because the changes have been sent to mongodb.

      I have looked the mongoid's source code and I saw this behavior on tests...This behavior is normal or a bug?

      Thanks for the great job.

            Assignee:
            durran Durran Jordan
            Reporter:
            lucasas lucasas
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: