I am building a Grails application and I am getting some weird results with integration testing when switching from the MongoDB GORM plugin to the Hibernate plugin.
I have a Client and Workspace class in a one to many relationship:
class Client{
//fields...
static hasMany = [workspaces: Workspace]
}
class Workspace{
//fields...
static belongsTo = [client: Client]
}
Then when running the following Spock integration test:
def "Deleting a client removes its related workspaces" () {
given: "An existing client and workspace"
Client client = new Client().save(failOnError: true)
Workspace workspace = new Workspace().save(failOnError: true)
client.addToWorkspaces(workspace)
when: "Deleting the client"
def foundClient = Client.get(client.id)
foundClient.delete(flush: true)
assert !Client.exists(client.id)
then: "Related workspace is also deleted"
!Workspace.exists(workspace.id)
}
This test will pass with Hibernate but not with MongoDB running. MongoDB will not delete the workspace and the last line of the test will fail as such:
Workspace.count() == 0
| |
1 false
Is there a way for MongoDB to perform the same cascading operations as Hibernate using GORM?
Thanks for your help