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

save after invalid embedded association creation

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      If this is a duplicate, I'm sorry in advance. If document has an invalid embedded association, it cannot save other attributes.

      class Item
        include Mongoid::Document
      
        embeds_many :urls
        field :title
      end
      
      class Url
        include Mongoid::Document
      
        embedded_in :item
        field :value
        validates :value, uniqueness: true
      end
      
      describe Item do
        it 'does not save title' do
          item = Item.create
          item.urls.create(value: 'url')
          item.urls.create(value: 'url')
          expect(item.update_attributes(title: 'title')).to eq false
        end
      end
      

      reload solve this problem. But this is expected? If this is, I'm OK and please close this issue. I just want to inform this behavior. Thank you.

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

              Created:
              Updated:
              Resolved: