meilisearch / meilisearch-rails

Meilisearch integration for Ruby on Rails
https://www.meilisearch.com
MIT License
295 stars 48 forks source link

Undefined method `after_destroy_commit' when using with Mongoid #359

Closed DeathKing closed 3 months ago

DeathKing commented 3 months ago

Description I have a model like this:

class Policy
  include Mongoid::Document
  include Mongoid::Timestamps

  include MeiliSearch::Rails
  # extend Pagy::Meilisearch

  meilisearch do
    searchable_attributes [:title, :content_text]
  end

When I use Policy.reindex!, it shows:

/opt/homebrew/lib/ruby/gems/3.3.0/gems/meilisearch-rails-0.13.0/lib/meilisearch-rails.rb:464:in `meilisearch': undefined method `after_destroy_commit' for class Policy (NoMethodError)

            after_destroy_commit { |searchable| searchable.ms_enqueue_remove_from_index!(ms_synchronous?) }
            ^^^^^^^^^^^^^^^^^^^^
Did you mean?  after_destroy

Expected behavior What you expected to happen.

Current behavior What happened.

Screenshots or Logs If applicable, add screenshots or logs to help explain your problem.

Environment :

DeathKing commented 3 months ago

Solved by adding

include ActiveRecord::Transactions