On Nov 13, 6:14 pm, Norbert Melzer <[email protected]> wrote:

> OK, here the problem:
>
> I have the model "Item" and every "Item" should be craftable. Therefore it
> needs "Ingredients", this "Ingridients" are "Items" too.
>
> Given Item "Flour"
> And Item "Water"
> When I mix it
> Then I should have the Item "Dough"
>
> But it is not that easy (the above example is complicated enough for me).
>
> Since the Items have all a unit of messurement (Water is litre, Flour is
> kilograms) I only want to have fractions in the receipe list.
>
> Something like that:
> 1kg Flour + 0.25 litre Water = 1.25 kg Dough
>
> I really dont know how to do the migration and model for that "Recipe"
>
> Of course there are Items that dont have ingredients (How could I assemble
> something into water?) or are not needed as Ingredient anymore (What should
> I build with a skyscraper?)
>

Just off the top of my head:

an item model, which should have some attributes like what units to
use with it, whether it can be combined with other things, and whether
it is primitive (like your example of water. That might be debatable -
you can make water by mixing hydrogen and oxygen, or you might say
that you get fresh water by desalinating sea water).

Your next model could be an ItemQuantity: an item plus a quantity
(i.e. water, 0.25L) (i.e. item_quantity belongs_to :item), which
reflects a specific use of a certain item in a recipi

Then you could have a step model, where a step is a series of item
quantities, perhaps an action, i.e. uses: water 0.25L, flour 1kg,
action:mix and then a second list of item quantities: the items that
are produced, and in which quantities. You might want action to be a
separate model (perhaps contain explanations of the specific process,
e.g. cream versus fold versus beat etc.)

An Item quantity could have 2 foreign keys pointing a step. The first
would indicate that it is one of the inputs to that step, the second
would mark that it is the output of a step (and obviously an item
quantity might be the output of one step and the input of another,
although never input and output for a single step.

A recipe would then be an ordered list of steps.

You should also think about what you are going to do with these
modelled items - what are the queries you are going to want to run
against your database? If the structure you come up with makes
important queries very difficult or slow then it's worth looking at
whether you can organise your data differently

Fred

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to