Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3963326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:12:07+00:00 2026-05-20T03:12:07+00:00

I have a Product model: class Product < ActiveRecord::Base belongs_to :subcategory define_index do #

  • 0

I have a Product model:

class Product < ActiveRecord::Base
    belongs_to :subcategory

    define_index do

        # fields
        indexes subcategory.name, :as => :subcategory, :sortable => true, :facet => true

        # attributes
        has subcategory_id, created_at, updated_at

        #properties
        set_property :delta => true

Now, suppose that a user updates a subcategory name, which is the proper way to update the products delta index?

According to this documentation: http://freelancing-god.github.com/ts/en/deltas.html, a save message should be sent to the product, so in this case I should go for each product related with the subcategory and send the save message, something like this:

class Subcategory < ActiveRecord::Base
    has_many :products

    after_save :set_product_delta_flag

    private

    def set_product_delta_flag
        products.each { |product|
        product.delta = true
        product.save
     }
    end
  end

I think that this is overkilling because we have like 100.000 products per subcategory.
Is this the correct way to update the delta index? Am I missing something?

After adding this:

def set_product_delta_flag
    Product.update_all ['delta = ?', true], ['subcategory_id = ?', id]
    Product.index_delta
end

I’m always receiving this error:

NoMethodError (undefined method `index_delta’ for #):

So, the solution to this problem was to send the message *define_indexes* to the Product model.

After fixing this issue, everything was ok, but the delta_index was not correctly updated, I needed to do save twice to the subcategory model.

So my final solution is this one:

after_commit :set_product_delta_flag

private

def set_product_delta_flag
    Product.define_indexes
    Product.update_all ['delta = ?', true], ['subcategory_id = ?', id]
    Product.index_delta
end

Using after_commit and define_indexes is the correct solution? Its the only one that I’ve found.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:12:07+00:00Added an answer on May 20, 2026 at 3:12 am

    Try the following instead:

    def set_product_delta_flag
      Product.update_all ['delta = ?', true], ['subcategory_id = ?', id]
      Product.index_delta
    end
    

    A single SQL statement, a single delta re-indexing. Should perform far better 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model class as shown below: class Product < ActiveRecord::Base belongs_to :user;
I have the following models: class Product < ActiveRecord::Base belongs_to :brand belongs_to :model accepts_nested_attributes_for
i have following model setup class Category < ActiveRecord::Base has_ancestry :cache_depth => true, :depth_cache_column
I have the following models: class Price < ActiveRecord::Base belongs_to :product end class Metric
I have the following model associations: class Product < ActiveRecord::Base has_many :prices class Price
I have the following two models: class Product < ActiveRecord::Base belongs_to :shop validates_numericality_of :price,
I have 2 models class Variant < ActiveRecord::Base belongs_to :product with_options :if => :is_active?
I have the following models: class Infoset < ActiveRecord::Base belongs_to :infosetable, :polymorphic => true
I have the following model structure: class Group < ActiveRecord::Base has_many :group_products, :dependent =>
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.