0

I have a complex object 'Variant' which has many associations. Something on these lines.

class Spree::Variant
  belongs_to :product
  has_many :variant_properties
end

class Spree::Product
  has_many :variants
  has_many :properties
end

On a page I want to display many variant objects which needs all the product/variant associations and properties. I was using elasticsearch earlier to create a unified view which would encapsulate all this data into one object. On variant save, elasticsearch would update its index with the changed mapped values.

Now I wish to remove elasticsearch and fetch all the data via activerecord. but creating the object with all the data would require a lot of database calls.

Is there a way so I can have the de-normalized object using ActiveRecord?

kitwalker
  • 862
  • 1
  • 10
  • 29

1 Answers1

0

You must use something like Spree::Product.last.includes(:variants).variants It explained here