I have a table called “Itemlist” and have multiple columns in it such as
“item1”, “item2”, “item3”, “item4”. These columns often have repetitious
data between them and I’m trying to count it. The only working code I
have so far is:
And this works fine for retrieving the count for “Apple” in all the
:item1 fields, but I need to retrieve the count for “Apple” from the
columns :item2, :item3, and :item4 as well as :item1. Any ideas? Thanks!
And this works fine for retrieving the count for “Apple” in all the
:item1 fields, but I need to retrieve the count for “Apple” from the
columns :item2, :item3, and :item4 as well as :item1. Any ideas?
Thanks!
That looks like a fundamentally different operation, counting apples,
rather than lists that contain apples. Won’t any list containing
multiple apples be over-counted?
code I
apple_query = item_ids.map {|id| “item#{id} = ‘Apple’” }.join(" OR
list: string
has_many :item_list_items
multiple apples be over-counted?
Oh, I thought that’s what you implied by “but I need to retrieve the
count for “Apple” from the columns :item2, :item3, and :item4 as well
as :item1.”
If you want the count of ItemList that have at least one ItemListItem
that is “Apple”, that would be: