# Overriding default values - model advice

**URL:** <https://www.ruby-forum.com/t/overriding-default-values-model-advice/141477>\
**Category:** Rails\
**Created:** [June 26, 2008, 8:28am UTC](https://www.ruby-forum.com/t/overriding-default-values-model-advice/141477 "2008-06-26T08:28:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 26, 2008, 8:28am UTC](https://www.ruby-forum.com/t/overriding-default-values-model-advice/141477/1 "2008-06-26T08:28:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 26, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/overriding-default-values-model-advice/141477/2 "2008-06-26T12:19:26Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [June 27, 2008, 9:06am UTC](https://www.ruby-forum.com/t/overriding-default-values-model-advice/141477/3 "2008-06-27T09:06:52Z")

</div>

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!
