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

Update indexes when associated entities are modified #139

Closed
wants to merge 2 commits into from
Closed

Update indexes when associated entities are modified #139

wants to merge 2 commits into from

Conversation

m-r-c
Copy link

@m-r-c m-r-c commented Jan 25, 2016

The current version of the plugin (0.0.4.6) does not trigger an index update when modifying/inserting/deleting associated entities (e.g. from a one-to-many relationship).

For example, in the following dummy structure, updating an instance of B directly will not trigger an index update.

class A {
  static searchable = {
    children component: true
  }

  String name
  static hasMany = [children: B]
  ...
}

class B {
  static searchable = {
    root = false
  }

  String name
  static belongsTo = [parent: A]
  ...
}

...
A a = new A()
B b1 = new B()
B b2 = new B()
a.children << b1
a.children << b2

a.save() // index updated

a.name = 'bla'
a.save() // index updated

b1.name = 'b1'
b1.save() // index NOT updated

This is due to the following code from AuditEventListener.groovy

if (elasticSearchContextHolder.isRootClass(entity.class)) {
  pushToIndex(entity)
}

The associated entity is not the root class for the index, and so no updates are triggered.

The change in this pull request will traverse the entity relationship hierarchy (as long as the associated entities have back references to their parent) to find the root entity.

@puneetbehl
Copy link
Collaborator

Merged into 0.1.x. Could you please update the documentation as well?

@puneetbehl puneetbehl closed this Jul 10, 2016
@puneetbehl puneetbehl added this to the v0.1.1 milestone Jul 10, 2016
@puneetbehl puneetbehl self-assigned this Jul 10, 2016
@yoga1982
Copy link

can i ask why this change is not merged to the version 1.2?

@puneetbehl
Copy link
Collaborator

Merged to v1.2.1

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

Successfully merging this pull request may close these issues.

None yet

3 participants