I have a Resource model with attribute subcategory_list, which is a comma-separated list of subcategories. Is it possible to do a find_by_x method (or equivalent) that pulls only those resources that belong to a certain subcategory?
So if given:
Resource.create(subcategory_list: "Fun, Games") # resource 1
Resource.create(subcategory_list: "Fun") # resource 2
Resource.create(subcategory_list: "Games") # resource 3
I would need a query to get both resources 1 and 2 when my input is “Fun”. I can return ONLY “Fun” but not “Fun, Games” with the following
Resource.find_all_by_subcategory_list("Fun")
=> resource 2 (but not resource 1)
Is there a way to modify this query to include “Fun, Games” as well?
If
subcategory_listis a comma-seperated string:If
subcategoryis an associated model: