MongoDB Plugin
  1. MongoDB Plugin
  2. GPMONGODB-187

delete doesn't cascade from the owner in one-to-many relation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.0.0.RC4
    • Fix Version/s: 1.1.0.GA
    • Environment:
      Grails 2.0.1, Ubuntu 10.04 LTS 64 bit, MongoDB 2.0.3, Java 1.7.0_03
    • Testcase included:
      yes

      Description

      delete on a one to many relationship does not delete its dependents, when belongsTo is defined.

      for instance, creating a User, which has many UserSettings:

      class User {
      
      	ObjectId id
      	
      	String name
      
      	static hasMany = [settings:UserSettings]
      	
          static constraints = {
          }
      }
      
      class UserSettings {
      
         ObjectId id
      
         boolean someSetting = true 
      
         static belongsTo = [user:User]
      	
      }
      

      Integration test: (UserSetting remains after User is deleted)

      	void test_user_settings() {
      		def u = new User(name:"user2")
      		def s = new UserSettings()
      		u.addToSettings(s)
      		
      		u.save(flush:true)
      
      		def found1 = User.findByName("user2")
      		assertNotNull found1
      
      		def found1a = UserSettings.findByUser(found1)
      
      		assert found1.settings.size()  == 1
      		
      		found1.delete(flush:true)
      
      		def found2 = User.findByName("user2")
      		assertNull found2
      
      		def found1b = UserSettings.findByUser(found1)
      		// THIS ONE FAILS
      		assertNull found1b
      	}
      

        Activity

        Hide
        James Hardwick added a comment -

        I can also confirm this on OSX Mountain Lion w/ Grails 2.1.1, MongoDB 2.2.2, and MongoDB GORM 1.0.0.GA.

        This seems to me like a greater than "Major" priority ticket.

        Show
        James Hardwick added a comment - I can also confirm this on OSX Mountain Lion w/ Grails 2.1.1, MongoDB 2.2.2, and MongoDB GORM 1.0.0.GA. This seems to me like a greater than "Major" priority ticket.
        Hide
        Droggo added a comment -

        This seems to be still not working. Check http://stackoverflow.com/questions/14393748/grails-2-1-0-mongodb-on-delete-cascade-not-working#comment20095333_14393748

        I also did test and it fails on the last assert:

        class Category {
            ObjectId id
            String name
        	
            static hasMany = [products:Product]
        
            static mapWith = 'mongo'
        	
            static constraints = {
            }
        }
        
        class Product {
            ObjectId id
            String name
        
            static belongsTo = [category:Category]
        
            static mapWith = 'mongo'
        
            static constraints = {
            }
        }
        
        def fantasy = new Category(name:'Fantasy')
        fantasy.addToProducts(new Product(name:'BookA'))
        fantasy.addToProducts(new Product(name:'BookB'))
        fantasy.save(flush:true)
        
        assert Category.findByName('Fantasy').products.size() == 2
        
        Category.findByName('Fantasy').delete(flush:true)
        assert Product.count() == 0
        
        Show
        Droggo added a comment - This seems to be still not working. Check http://stackoverflow.com/questions/14393748/grails-2-1-0-mongodb-on-delete-cascade-not-working#comment20095333_14393748 I also did test and it fails on the last assert: class Category { ObjectId id String name static hasMany = [products:Product] static mapWith = 'mongo' static constraints = { } } class Product { ObjectId id String name static belongsTo = [category:Category] static mapWith = 'mongo' static constraints = { } } def fantasy = new Category(name:'Fantasy') fantasy.addToProducts( new Product(name:'BookA')) fantasy.addToProducts( new Product(name:'BookB')) fantasy.save(flush: true ) assert Category.findByName('Fantasy').products.size() == 2 Category.findByName('Fantasy').delete(flush: true ) assert Product.count() == 0
        Hide
        Sukrit Khera added a comment -

        I ran into this issue today with Grails 2.3.0 and plugin: 1.3.0 . Can this issue be reopened ?

        Show
        Sukrit Khera added a comment - I ran into this issue today with Grails 2.3.0 and plugin: 1.3.0 . Can this issue be reopened ?

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            St.H
          • Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: