<p>This is a very difficult problem. And to be honest, I'm not sure if 3 dishes will actually cover the possible combinations in the way that you're asking. Just the common dietPreferences alone could result in 63 combinations (6+15+20+15+6+1). If you add allergens into the mix the numbers get very large very quickly.</p>

<pre><code>dietPreferences = ['beef', 'pork', 'chicken', 'fish', 'vegetarian', 'vegan'];
allergens = ['dairy', 'peanuts', 'gluten', 'shellfish', 'etc', 'etc'];
</code></pre>

<p>I think that you will need to reduce the combinations to something like ['redmeat(including chicken)', 'redmeat+fish', 'fish+vegetarian', 'vegetarian', 'all']; And then always have a meat, fish and vegetarian dish that do not include any allergens. Vegans would not be supported; nor would those allergic to dairy, gluten, and other ingredients that are difficult to avoid.</p>

<p>As far as a CMS goes however, craft is as capable as any CMS to tackle the problem, but you would need to establish the parameters carefully first.</p>

<p>For more information on relationships check out the documentation for <a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param" rel="nofollow">relatedTo</a>. You might also do a search on this site for 'relatedTo', 'advanced search' and 'elementCriteriaModel'.</p>

CC BY-SA 3.0
2015-01-06T03:10:35.520Z
2015-01-06T03:10:35.520Z
Douglas McDonald
<p>I am currently working on a project in EE that involves food delivery services and have run into a block. The project is about users subscribing to a plan and receiving a different dish every day of the week. During signup, users select their meat preferences and any items they're allergic to.</p>

<p>On the food side, when dishes are added, the type of meat in them is one field and ingredients (ones that users could be allergic to) is another. There will be about a couple of hundred dishes added in total.</p>

<p>What I would like to do is select 2-3 types of dishes daily and have them distributed to users based on their meat preference. With EE, I can't figure out of I can create a relationship based on multiple queries (such as select users that have chosen Vegetarian AND chicken or Select Users that have chosen Chicken but NOT vegetarian.) Would this be something Craft is capable of? And What would be the best way of picking a dish and then figuring out which users it can be assigned to and then picking the second dish and assigning to the remaining users and if need be, pick a third dish to assign any users that are left over?</p>

<relations>
Building relationships
# Building relationships

(Asked by: username_0 on 2014-12-29)

I am currently working on a project in EE that involves food delivery services and have run into a block. The project is about users subscribing to a plan and receiving a different dish every day of the week. During signup, users select their meat preferences and any items they're allergic to.

On the food side, when dishes are added, the type of meat in them is one field and ingredients (ones that users could be allergic to) is another. There will be about a couple of hundred dishes added in total.

What I would like to do is select 2-3 types of dishes daily and have them distributed to users based on their meat preference. With EE, I can't figure out of I can create a relationship based on multiple queries (such as select users that have chosen Vegetarian AND chicken or Select Users that have chosen Chicken but NOT vegetarian.) Would this be something Craft is capable of? And What would be the best way of picking a dish and then figuring out which users it can be assigned to and then picking the second dish and assigning to the remaining users and if need be, pick a third dish to assign any users that are left over?

**Tags:** relations

---

## 1 answers

### Answer by username_1 on 2015-01-06. Score: 2

This is a very difficult problem. And to be honest, I'm not sure if 3 dishes will actually cover the possible combinations in the way that you're asking. Just the common dietPreferences alone could result in 63 combinations (6+15+20+15+6+1). If you add allergens into the mix the numbers get very large very quickly.
dietPreferences = ['beef', 'pork', 'chicken', 'fish', 'vegetarian', 'vegan'];
allergens = ['dairy', 'peanuts', 'gluten', 'shellfish', 'etc', 'etc'];

I think that you will need to reduce the combinations to something like ['redmeat(including chicken)', 'redmeat+fish', 'fish+vegetarian', 'vegetarian', 'all']; And then always have a meat, fish and vegetarian dish that do not include any allergens. Vegans would not be supported; nor would those allergic to dairy, gluten, and other ingredients that are difficult to avoid.
As far as a CMS goes however, craft is as capable as any CMS to tackle the problem, but you would need to establish the parameters carefully first.
For more information on relationships check out the documentation for relatedTo. You might also do a search on this site for 'relatedTo', 'advanced search' and 'elementCriteriaModel'.


---

