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

isDirty on many-to-many relationship doesn't work #1536

Open
xpusostomos opened this issue Oct 2, 2021 · 0 comments
Open

isDirty on many-to-many relationship doesn't work #1536

xpusostomos opened this issue Oct 2, 2021 · 0 comments

Comments

@xpusostomos
Copy link

I would like to resurrect a previously reported bug...

grails/grails-core#11321

Because I for one can't see how there is not some kind of bug here.

According to the documentation http://gorm.grails.org/6.0.x/hibernate/manual/#modificationChecking

"isDirty() does not currently check collection associations, but it does check all other persistent properties and associations."

But the documentation doesn't tell you how to make these associations save, since apparently it can't detect changes automatically.

Person person = Person.findByName('alber2')
Position position = Position.findByName('boss2')
person.addToPositions(position)

This does not save the new relationship.

In the 1:M case, lack of auto dirty checking doesn't seem such a problem because one of the visible tables will have changed and will be dirty. But in the M:M case, the table that needs to change is the invisible table position_person that's automatically populated.

One can't call markDirty() on the intervening position_person table, because it's invisible to the programmer in the infrastructure.

I've tried marking the owning table and subordinate tables as dirty:

Person person = Person.findByName('alber2')
Position position = Position.findByName('boss2)
person.addToPositions(position)
position.markDirty()
person.markDirty()
But that doesn't work. person.isDirty() still returns false, and the relationship doesn't save.

How is this supposed to work? How can I get the relationship to save?

  • GORM Version: 6.1.12
  • Grails Version (if using Grails): 3.3.14
  • JDK Version: 1.8

Example Application

There is an example app here grails/grails-core#11321

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

No branches or pull requests

1 participant