Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class MongoCodecEntityPersister extends ThirdPartyCacheEntityPersister<Object> {
if (proxyFactory.isInitialized(value)) {
def dirtyCheckable = (DirtyCheckable) value
if (dirtyCheckable.hasChanged()) {
if (!isUpdate || association.isOwningSide() || association.doesCascade(CascadeType.PERSIST)) {
if (association.isOwningSide() || association.doesCascade(CascadeType.PERSIST)) {
mongoCodecSession.persist(value)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package grails.mongodb.cascade

import grails.gorm.tests.GormDatastoreSpec

class MongoCascadeSpec extends GormDatastoreSpec {

@Override
List getDomainClasses() {
[Product, ProductLine]
}

void "test association is not cascaded on update or insert"() {
given:
ProductLine x = new ProductLine(name: "x")
x.save()
session.flush()
session.clear()

Product product = new Product(name: "my product", productLine: ProductLine.load(x.id))
product.save()
session.flush()
session.clear()

when:
product = Product.get(product.id)

then:
product.productLine.name == "x"

when: //no cascading on update
product.productLine.name = "xy"
product.save()
session.flush()
session.clear()
x = ProductLine.get(x.id)

then:
x.name == "x"

when:
x.name = "xy"
product = new Product(name: "other product", productLine: x)
product.save()
session.flush()
session.clear()

then:
ProductLine.get(x.id).name == "x"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package grails.mongodb.cascade

import grails.persistence.Entity


@Entity
class Product {

String name
ProductLine productLine

static mapping = {
productLine(cascade: "none")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package grails.mongodb.cascade

import grails.persistence.Entity

@Entity
class ProductLine {

String name

}