Lubomir Herko

Joined

1,170 Experience
11 Lessons Completed
0 Questions Solved

Activity

Posted in Rails view_components

+1

Posted in Searchkick Aggregation for has_many_through association

Hey guys,

I have an ecommerce product catalogue, where I store products, product options and option values in this kind of fashion:

# models/product.rb
has_many :option_values
has_many :option_types, through: :option_values

# models/option_value.rb
belongs_to :option_type
belongs_to :product

#models/option_type.rb
has_many :option_values
has_many :products

I came up with this structure so I can have for example a lamp Product that can be connected to OptionType titled "Power supply included" via value OptionValue set to true. Data in database for this product are saved as follows:

#products
id: 22
title: "A lamp"

#option_values
id: 1
option_type_id: 5
product_id: 22
value: true

#option_types
id: 5
title: "Power supply included"

Every ProductCategory has its own specific set of option values, that's why I came up with this structure, it is inspired by Spotify architecture and I will need this in search/aggregates/filters, what leads me to my question:

How can i create aggregate search so I can select all products, that have "Power supply included" set to true? Do I need nested aggregates, or do I setup search_data in some fashion so I can access them via aggs?

Posted in Global Autocomplete Search Discussion

SHouldn't jquery and all dependencies be in /vendor/assets/javascripts folder? Just asking.. I thouhgt that is the 'recommended way'..