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

Stack level too deep on validates_presence_of

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

      Hi Guys,

      I have the following models:

      class A
        include Mongoid::Document
      
        after_save :x
      
        belongs_to :b
      
        def x
          B.create a: self
        end
      end
      
      class B
        include Mongoid::Document
      
        has_one :a
      
        validates_presence_of :a
      end
      

      Then, I create an instance of

      Unable to find source-code formatter for language: a. 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
      .create

      and I got an stack level too deep. This happen because the method

      Unable to find source-code formatter for language: validates_presence_of```. 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
       save the new instance of 

      A

       (autosave is enabled by default: https://github.com/mongoid/mongoid/issues/1675). But the callback is invoked after the object was created.
      
      If I set 

      autosave: false

       the method 

      validates_presence_of

       does not save 

      A

       instance. This is a bug? Or I should set 

      autosave: false{{`}}?

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

              Created:
              Updated:
              Resolved: