belongs_to multiple things

Nick Green wrote:

We have restaurants. Each restaurant has many menus. Each restaurant
has many dishes. Every dish /must/ belong to a menu, and every dish
/must/ belong to a restaurant (conceptually). The same dish cannot
belong to 2 different menus or restaurants (a dish with all the same
attributes could, but in the DB its a different dish).

I could be misreading your design specifications here, but it seems to
me that restaurants would have many dishes through menus:

class Restaurant
  has_many :menus, :dependent => :destroy
  has_many :dishes, :through => :menus
end

class Menu
  belongs_to :restaurant
  has_many :dishes, :dependent => :destroy
end

class Dish
  belongs_to :menu
end

Then you could do things like:
restaurant.menus
restaurant.dishes
menu.dishes
dish.menu.restaurant

Precisely what I'm looking for. I thought I must be missing something,
somehow reading books/tutorials all at once my brain just lets some
information go, and I couldn't remember the pertinent info, but I could
tell my way was not "railsish".

Sorry for the silly question and thanks for the answer :slight_smile:

Robert Walker wrote:

Thanks for asking the question, it helped me understand things better.