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

accepts_nested_attributes_for - reject_if: :all_blank not working

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

      class Product
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :name
      
        embeds_one :seo, as: :seo_tags, cascade_callbacks: true, autobuild: true
        accepts_nested_attributes_for :seo, reject_if: :all_blank
      end
      
      class Seo
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :title
      
        embedded_in :seo_tags, polymorphic: true
      end
      

      The problem is that, when I create product, with blank seo fields - seo is saved. I'm running Rails 3.2.11 and Mongoid 3.0.21.

      irb(main):001:0> p = Product.create name: "Hello"
      => #<Product _id: 511386d0c185641c9c000002, name: "Hello", created_at: 2013-02-07 10:49:52 UTC, updated_at: 2013-02-07 10:49:52 UTC>
      irb(main):002:0> p.seo
      => #<Seo _id: 511386d0c185641c9c000001, _type: nil, title: nil, keywords: nil, description: nil, noindex: nil, nofollow: nil>
      irb(main):003:0> p.seo.persisted?
      => true
      

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

              Created:
              Updated:
              Resolved: