Maybe thats not directly a solidus question but ra...
# support
m
Maybe thats not directly a solidus question but rather a rails question but maybe it's gonna be simple enough for anyone of you to just answer it quickly: I have to fetch all the line items associated with products from a specific taxon. Here is my method chain to do that:
Copy code
Spree::LineItem
  .includes(variant: { product: :taxons })
  .where(spree_variants: { spree_products: { spree_taxons: { id: [413, 429] } } })
however, sadly, it's giving me
Copy code
undefined method `key?' for nil:NilClass (NoMethodError)

      klass&.columns_hash.key?(column_name)
error (which looks like some unhandled internal rails case) so there is something wrong either with includes or with all these nested where conditions but i already spent couple of hours trying to understand what the issue might be and i reached dead end. Can you see anything wrong with my query method chain? I would really appreciate your help with this one ๐Ÿ™
k
thereโ€™s a join table between products and taxons, which is called classifications. I think the issue is there.
c
@m b You don't need to repeat all the table names in the
where
Copy code
Spree::LineItem.includes(variant: { product: :taxons }).where(spree_taxons: { id: [413, 429] })
m
thank you! Funny thing with that - the above code works but adding
not
after
where
(which is what i actually need, i just simplified the question) doesn't return proper line items. It returns these with the unwanted taxons anyway
c
I think that may be because you are doing an outer join with
includes
maybe try using
joins
instead
m
ah, this is interesting. Thank you! I will try tis ๐Ÿ™‚
c
It returns these with the unwanted taxons anyway
Are you saying that it's not excluding the taxon id's like you expect?
A product can have multiple taxons, so you'll still get line items even if they are not associated with these taxons, if they are associated with other taxons, the way you've got your query
Because you are only excluding the rows that are associated with the specified taxons, not any other taxons. I hope that makes sense.
If you wanted only line items that are for products that don't have these taxons you may need to use a subquery to first get all products that have these taxons and then exclude line items for those products.
m
that's pretty much how i handled that so far ๐Ÿ™‚
๐Ÿ‘๐Ÿผ 1