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 Index Derived from Multiple Associated Models #918

Open
jvanderen1 opened this issue Dec 27, 2023 · 0 comments
Open

Update Index Derived from Multiple Associated Models #918

jvanderen1 opened this issue Dec 27, 2023 · 0 comments

Comments

@jvanderen1
Copy link

As a developer, I would like to see an example of an index which is derived from multiple Ruby models. Based on the documentation today, I only see indices with a single index_scope defined. I am actually not sure if it is possible today, but I would like to update my Elasticsearch documents multiple-model associations:

class Employee < ActiveRecord::Base
  # TODO: How to update specific `restaurant` document(s)?
  # update_index('restaurant') { ??? }
end

class Cuisine < ActiveRecord::Base
  # TODO: How to update specific `restaurant` document(s)?
  # update_index('restaurant') { ??? } 
end

class Restaurant < ActiveRecord::Base
  has_many :employees
  has_many :cuisines

  update_index('restaurant') { self }
end

class RestaurantsIndex < Chewy::Index
  index_scope Restaurant
end

In this contrived example, a Restaurant would have a foreign key relationship with Employee and Cuisine, but an Employee nor a Cuisine do not necessarily belong to a Restaurant. Therefore, when the associated records update, the RestaurantsIndex would miss these updates, correct? How can we ensure our index is always up-to-date with our DB record associations?

I did come across #34 before making this issue. However, this seems to reference an older syntax / version of Chewy.

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