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

When embedded autobuilt association is required to be present, document is persisted without the association making it invalid

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 7.1.0
    • Component/s: Persistence, Validations
    • Environment:
      Fedora 32 (x86-64)
      Ruby: 2.7.1
      Bundler: 2.1.4
      MongoDB: MongoDB 4.2.8 Community
      Mongodb Cluster: standalone

      If we have two models, one is embedded to another.

      We attached validation to parent and embedded ones.

       

      If parent fields are valid, but embedded ones are invalid, `create!` method won't raise exception and create model into DB.

       

      Steps to reproduce.

      • boot to any Linux distributive
      • install ruby, bundler, mongodb, start mongodb
      • unpack attached archive, cd to it
      • run `bundler install`
      • run `bundler exec ruby ./all_is_well.rb`, see validation error as expected
      • run `bundler exec ruby ./doesnt_throw_as_expected.rb`, see no validation error
        •  sorry, I can't setup it to work without Rails, so it shows another exception, but in Rais it just creates model. But if to check it later: `instance.valid?` - it returns false

            Assignee:
            Unassigned Unassigned
            Reporter:
            vlad1777d@gmail.com Vlad Niora
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: