<p>In essence, if I am reading that right, can you reverse the question?  I.e. it seems that what you want to know is, for each accessory in the cart, is there a reverse relation back to at least one product in the cart.</p>

<p>This is definitely possible - you can read about reverse relations here: <a href="https://straightupcraft.com/articles/introduction-to-relations-and-reverse-relations-in-craft-cms-with-examples" rel="nofollow noreferrer">https://straightupcraft.com/articles/introduction-to-relations-and-reverse-relations-in-craft-cms-with-examples</a> and of course at <a href="https://craftcms.com/docs/relations" rel="nofollow noreferrer">https://craftcms.com/docs/relations</a></p>

<p>..basically just loop through each accessory and check the <code>|length</code> of the result of a <code>relatedTo</code> that specifies what you want it to be related to (.e.g a product category).</p>

CC BY-SA 3.0
2017-03-09T23:41:37.843Z
2017-03-09T23:41:37.843Z
Jeremy Daalder
<p>Folks:</p>

<p>In this scenario, a main product has multiple accessories (which are, of course, related to the main product through relationships). Only certain accessories are related to the main product. The user can place main products and unrelated accessories into the cart. I'd like to display a warning that they are ordering incompatible items.</p>

<p>I understand that you can use <code>empty</code> or <code>relatedTo</code> to find out if a relationship exists between entries but in this case, I need to know if accessories unrelated to the main product are in the cart.</p>

<p>Is this possible?</p>

<plugin-craftcommerce>
Verify if unrelated items are in the cart
# Verify if unrelated items are in the cart

(Asked by: username_0 on 2017-03-04)

Folks:

In this scenario, a main product has multiple accessories (which are, of course, related to the main product through relationships). Only certain accessories are related to the main product. The user can place main products and unrelated accessories into the cart. I'd like to display a warning that they are ordering incompatible items.

I understand that you can use `empty` or `relatedTo` to find out if a relationship exists between entries but in this case, I need to know if accessories unrelated to the main product are in the cart.

Is this possible?

**Tags:** plugin-craftcommerce


---

## 1 answers

### Answer by username_1 on 2017-03-09. Score: 1

In essence, if I am reading that right, can you reverse the question? I.e. it seems that what you want to know is, for each accessory in the cart, is there a reverse relation back to at least one product in the cart.

This is definitely possible - you can read about reverse relations here: <https://straightupcraft.com/articles/introduction-to-relations-and-reverse-relations-in-craft-cms-with-examples> and of course at <https://craftcms.com/docs/relations>

..basically just loop through each accessory and check the `|length` of the result of a `relatedTo` that specifies what you want it to be related to (.e.g a product category).


---

