1

Is isDirty() method not supported in grails mongodb plugin? I saw a comment in this link but it was commented 2 years ago. Just to know, if current version supports it?

Using grails 2.3.5 with mongodb 3.0.1 and no hibernate installed.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
  • Yes, actually I tried it after. But its behavior is a bit different. It returns true if I assign one property value same as its current value. Also dirty detection doesn't works for embedded data. – Shashank Agrawal Jul 15 '14 at 04:15
  • Shashank, looks like mongodb 3.0.1 is working for you. Please view my question http://stackoverflow.com/questions/29278975/cant-run-grails-app-with-mongodb-plugin-version-3-0-3 in case you have also encountered my issue. Thanks – Alexander Suraphel Mar 27 '15 at 07:04

2 Answers2

0

Okay got it working. It works but has a different behavior. If an existing property is binded & there is no any change in the value after binding then, isDirty() returns true. But if property is not at all binded then isDirty() works fine.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
0

Why not write something like User.collection?.findOne(this.id)?.password != password. It detects if the password field has changed.

Alexander Suraphel
  • 10,103
  • 10
  • 55
  • 90
  • Thank you Alexander for your response but following your code will make another query to the database. Also, since I wanted to use the isDirty() method in a database event, it may fail for locking exception. – Shashank Agrawal Mar 27 '15 at 09:33
  • @ShashankAgrawal Aha. So what exactly did you do to make `isDirty()` work? – Alexander Suraphel Mar 27 '15 at 12:01
  • 1
    `isDirty()` method works but in a bit different fashion like I mentioned in my above answer which was not exactly solving my problem. So I dig into the grails data mapping code for grails data core and mongodb and I found that, there is a property available in domain instance named `$changedProperties`in the pre-update event. I used that to compare the value and get to know if the particular field has an updated value. – Shashank Agrawal Mar 27 '15 at 12:21
  • @ShashankAgrawal so why not post is as an answer here? – Alexander Suraphel Jun 08 '15 at 16:07