chka opened a new issue, #14405:
URL: https://github.com/apache/grails-core/issues/14405

   I have the following self referencing domain class:
   
       package com.test
       
       import org.bson.types.ObjectId
       
       class Category {
           ObjectId id
           String name
           Category parent = null
           static hasMany = [childs: Category]
           static mappedBy  = [ childs: 'childs' ]
       }
   
   Then, I create 2 "Category" objects, where the 2nd object becomes child of 
the first, like this:
   
       def c1 = Category.findByName('category1') ?: new Category(name: 
'category1').save(failOnError: true)
       def c2 = Category.findByName('category2') ?: new Category(name: 
'category2', parent: c1).save(failOnError: true)
       c1.addToChilds(c2).save(failOnError: true)
   
   The outcome, is not what I expect and it appears that both objects become 
the child of the another:
   
       {
           "_id" : ObjectId("5b8d0ba306425e3ee4ff5cf9"),
           "name" : "category1",
           "version" : NumberLong(0),
           "childs" : [ 
               ObjectId("5b8d0ba306425e3ee4ff5cfa")
           ]
       }
       
       {
           "_id" : ObjectId("5b8d0ba306425e3ee4ff5cfa"),
           "name" : "category2",
           "version" : NumberLong(0),
           "childs" : [ 
               ObjectId("5b8d0ba306425e3ee4ff5cf9")
           ],
           "parent" : ObjectId("5b8d0ba306425e3ee4ff5cf9")
       }
   
   And while I can simply ignore children that are also parents, why I get this 
odd behavior?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to