Skip to content

Instantly share code, notes, and snippets.

@nickhoffman
Created January 4, 2012 21:23
Show Gist options
  • Save nickhoffman/1562222 to your computer and use it in GitHub Desktop.
Save nickhoffman/1562222 to your computer and use it in GitHub Desktop.
How to find filterable values when each result can have different filterable fields

Say you have an online store, and each product belongs to one catalog. In each catalog, you specify what custom attributes its products have. Eg:

  • Catalog: Transformers
    • Product Attributes: Character, Allegiance
  • Catalog: Games
    • Product Attributes: Number of Players, Average Game Time

When viewing a catalog, you want to enable users to filter by any custom product attribute. This is done by choosing which attribute to filter by from a dropdown, and then choosing the desired value for that attribute from a dropdown. Eg: filter products where “Character” is “Megatron”.

Here’s the question: How do you determine what values to put in the second dropdown?

Obviously, you can just iterate over each of the products in the catalog, gathering the values for each custom attribute. However, that requires you to load every product from the database. Yick.

The only alternative that I can think of is to store (in each catalog) the values for its products’ custom attributes.

@batasrki
Copy link

batasrki commented Jan 4, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment