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

Habtm and has_many relations not being validated

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

      UPDATE 2011-10-11

      The problem is that child documents in has-many relations that aren't loaded aren't validated when the parent is validated.


      ... as it states on http://mongoid.org/docs/relations/validations.html

      class Thing
        include Mongoid::Document
        embeds_many :ems
        embeds_one :eo
        has_many :hms
        has_one :ho
        has_and_belongs_to_many :habtms
      end
      class Em; include Mongoid::Document; embedded_in :thing; end
      class Eo; include Mongoid::Document; embedded_in :thing; end
      class Hm; include Mongoid::Document; belongs_to :thing; end
      class Ho; include Mongoid::Document; belongs_to :thing; end
      class Habtm; include Mongoid::Document; has_and_belongs_to_many :things; end
      
      [Thing, Em, Eo, Hm, Ho, Habtm].each do |klass|
        klass.before_validation {puts "** validating #{self.class}" }
      end
      
      em = Em.new
      eo = Eo.new
      t = Thing.create! :ems => [em], :eo => eo
      t.hms.create!
      t.create_ho
      t.habtms.create!
      

      (Sorry about the awful class/relation names.) Then:

      > t.reload.valid?
      ** validating Thing
      ** validating Em
      ** validating Eo
      ** validating Ho
       => true 
      

      So the

      Unable to find source-code formatter for language: habtm```. 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
       and 

      hm{{`}} are not validated.

            Assignee:
            Unassigned Unassigned
            Reporter:
            bensymonds Ben Symonds
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: