Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPMONGODB-315: Domain objects are persisted to DB without calling save() #306

Closed
graemerocher opened this issue Aug 20, 2013 · 0 comments
Closed

Comments

@graemerocher
Copy link
Member

Original Reporter: joshmandel
Environment: Grails 2.2.4
Version: 1.3.0.GA
Migrated From: http:https://jira.grails.org/browse/GPMONGODB-315

Forgive me if this is somehow expected behavior -- but I can't figure it out.

I'm seeing this behavior in my controllers in a simple grails app; though to reproduce it in an integration test I had to set:
static transactional = false

Basically, creating a new Value() and accessing a dynamic property causes the value to be persisted to the datastore, even without calling save():

        def v = new Value()
        assert Value.collection.find().count() == 0

        Value.count()
        assert Value.collection.find().count() == 0

        v.accessingDynamicProperty = 'should not trigger a save'
        assert Value.collection.find().count() == 0

        Value.count()
        assert Value.collection.find().count() == 0

Interestingly (to me), the saving appears to occur (in this integration test) as a side effect of calling Value.count() That is, if I leave out the Value.count() statements, this test will pass.

(In my actual grails app, the controller that creates this object doesn't call count(); it just creates a new object, sets a dynamic property, and renders a response.)

The attached .zip has a full test case that demonstrates the behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant