mercredi 25 mars 2015

grails domain mappedBy "none" not working on unit test

Currently using Grails 2.4.4


Im trying to save my models without them assuming bidirectional relationship. So I added mappedBy [field:'none']. But it is not working on unit test. It works when I run the app, but when I run unit test and save the domains, they always assume bidirectional relationship.


Consider example (I omitted the constraints for simplicity, consider the fields nullable):



class User {

Organization organization
static mappedBy = [organization: 'none']
}

class Organization {

User leader
static mappedBy = [leader: 'none']
}


Whenever I do a:



def user = new User().save()
def organization = new Organization(leader: user).save()
user.organization = organization
user.save()

def organization2 = new Organization(leader: user).save()
// now user's organization becomes organization2


Is this a bug? Is there a workaround for this?


Aucun commentaire:

Enregistrer un commentaire