I am looking for some advice in putting together the proper models and relationships in my application. My concern revolves around the requirement to have default prices, but allow them to be optionally overridable. The application involves clients choosing from menus of various dishes. Several menus are predefined and the client chooses the one they want to use. The models I''ve identified are Dish, Menu & Client. Menu has_many dishes and Client has_one menu. Dishes have a name and a default price. So far so good. Now the puzzle: What''s the best way to model the overriding of a dish''s price on a client by client basis? Clients are related to dishes through menus, but menus are shared across clients. I think I need another join table which stores dish_id, client_id and price. But then how to describe the relationship to rails? Thanks for any advice on this. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It would look like the menu thing. Only that it can be multiple prices. Can a Client have only one Menu? Seems a bit strange, but may depend on your app. Say you call the model ClientPrices Client model: has_many :client_prices Dishes: has_many :client_prices That''s all to it as far as I can see... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the reply. Yes the app calls for just one menu per client. I see where you''re going here. I think the logic below would complete things. Client.menu.dishes each do |dish| price = ClientPrices.find_by_client_and_dish(@client.id, dish.id) || dish.default_price end Thanks for the advice and let me know if you see any improvements! On Jun 26, 3:19 am, Thorsten Müller <thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote:> It would look like the menu thing. Only that it can be multiple > prices. > Can a Client have only one Menu? Seems a bit strange, but may depend > on your app. > > Say you call the model ClientPrices > > Client model: > has_many :client_prices > > Dishes: > has_many :client_prices > > That''s all to it as far as I can see...--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---