has_and_belongs_to_many OR self-joining association
I have a basic set up question for my nutrition application:
The application will have users who log in and receive MEAL prescriptions for the upcoming week. Tables can include:
Recipe (perhaps Meal)
1. I can have a has_and_belongs_to_many relationship between "Food" and "Recipe". Many recipes comprised of many foods.
2. I can use a self-joining association
class Meal < ActiveRecord::Base
has_many :foods, :class_name => "Meal",
:foreign_key => "recipe_id"
belongs_to :recipe, :class_name => "Meal"
I must remember the "User"... any need to consider polymorphic associations? The "User" will be prescribed "Meals" or "Recipes" on a weekly basis.
Thanks in advance.