Topic: Should use lots of separate models here?

Hi, I'm building an ordering app, for sandwiches. Order has many meals, meal has ingredients. Right now I have all the ingredients in a yaml file and a saved meal stores as yaml text in the meal model.

ingredients.yml

---
meat:
  - Chicken
  - Ham
  - Beef
  - Lamb

salad:
  - Lettuce
  - Tomato
  - Carrot
  - Olives
  - Onion

etc etc..


saved meal....
---
bread:
  - Multigrain

meat:
  - Chicken

salads:
  - Lettuce
  - Tomato
  - Pickles

cheese:
  - Cheddar

sauce:
  - Tomato


It's not optimal at all. I'm wondering if I should have a heap of separate models; salads, meat, cheese, sauce, seasoning, bread... it might be a bit of overkill though, the ingredients aren't likely to change often. What would be a better way to do it?

Any tips would be great, thanks.

Re: Should use lots of separate models here?

If your ingredients don't have varying attribs maybe acts as tree is something you can use
You have a parent_id in your tables and that way rails can sort your ingredients under different categories.

http://github.com/rails/acts_as_tree/tree/master

Re: Should use lots of separate models here?

Cheers, I'm looking into it....

Re: Should use lots of separate models here?

Saving your data in yaml inside the database is horrible.  I would probably just have a model called Ingredient which has a name (eg "Chicken") and a category (eg "Meat").  Then, have a join table which links meals and ingredients.

Didn't i give you the entire schema for this a week or two ago?  or was that someone else...

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams

Re: Should use lots of separate models here?

Hmm.. Must've been someone else, I've only posted here a couple times. Yeah, when I was doing it I knew it was ugly. I ended up with acts_as_tree, it does a mad job.