Hi,
Day 3 with rails here. Forgive me. If this has been covered many times
before, pls just point me at the article.
I worked through the Rolling with Rails tutorial
(http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html) built up my
cookbook. Things work great.
I now want to add Ingredients to my app. So, a Recipe will have 1 or
more Ingredients and any single ingredient can be referenced (belong
to?) any recipe.
How do I set up this relationship? With other languages I would create a
mapping table in my database which had two columns, a Recipe index and
Ingredient index. I could then write some simple SQL to pull all the
Ingredients for my Recipe or to get all the Recipes containing a
specific Ingredient. It doesn’t look like this is how it happens in
rails.
Do I modify my Ingredient class to have a ‘belongs_to_many’ relationship
to Recipe and Recipe to have a ‘has_many’ relationship to Ingredients?
How is this mapping done on the DB? What fields in the tables do I need
to add? Am I able to easily query the stuff mentioned above?
Thanks in advance,
Noah