Commit 7397e19ce7ac86d40a015efd648a33907fcb5ea8

Authored by Andrew Kane
1 parent a334ce83

Use previous changes [skip ci]

Showing 1 changed file with 1 additions and 4 deletions   Show diff stats
README.md
... ... @@ -1575,15 +1575,12 @@ Product.search("carrots", request_params: {search_type: "dfs_query_then_fetch"})
1575 1575  
1576 1576 Reindex conditionally
1577 1577  
1578   -**Note:** With ActiveRecord, use this feature with caution - [transaction rollbacks can cause data inconsistencies](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/README.md#custom-callbacks)
1579   -
1580 1578 ```ruby
1581 1579 class Product < ActiveRecord::Base
1582 1580 searchkick callbacks: false
1583 1581  
1584 1582 # add the callbacks manually
1585   - after_save :reindex, if: -> (model) { model.name_changed? } # use your own condition
1586   - after_destroy :reindex
  1583 + after_commit :reindex, if: -> (model) { model.previous_changes.key?("name") } # use your own condition
1587 1584 end
1588 1585 ```
1589 1586  
... ...