Hi!

I have a problem designing the following model. Better I have problems to
write the corresponding rails code to get that model up and running as
expected.

I tried several combinations of different tables, has_and_belongs_to
statements with several options with join_tables and I tried self joins,
etc... Really, I dont see a solution...

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?)

Could you help me?

TIA
Norbert Melzer

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/tWLjzi_50BQJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.

Search Discussions

  • Frederick Cheung at Nov 14, 2011 at 2:28 pm

    On Nov 13, 6:14 pm, Norbert Melzer 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 rubyonrails-talk@googlegroups.com.
    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.
  • Norbert Melzer at Nov 14, 2011 at 5:52 pm

    2011/11/14 Frederick Cheung <frederick.cheung@gmail.com>:
    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).
    In this particular abstraction of the world water is definitively a
    "primitiv" as you call it.
    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.
    I hope I will have some time this week to think about this and to
    understand it all.
    Neither english nor ruby are my native languages and im still
    learning. Especially all about databases drives me crazy in regular.
    It took me about 3 hours this morning to get a "simple" has_many up
    and running. Migrating a thousand times or so back and forth.

    I never know where to put the belongs_to and where the has_many, or
    how to set up the migrations, where to use singular and where plural.
    And after hours of trying and googling around, I found somewhere that
    I cant use "has_many :attributes" because of some reserved keyword
    stuff...
    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
    Every day use will be two types of query, only when a user requests it
    for a particular Item:

    1. What is the recipe for this item?
    2. In which recipes is this item used?

    And as I am writing this I am thinking about to allow production of
    fractional items for some cases. But I will wind a solution for this
    myself.

    A very seldom and only administrativ query would be to iterate over
    all items and build up a production graph.

    So far I thank you for your suggestions, I will post again if I have
    any problems.

    Norbert

    --
    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@googlegroups.com.
    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.
  • Colin Law at Nov 14, 2011 at 8:15 pm

    On 14 November 2011 17:51, Norbert Melzer wrote:
    I hope I will have some time this week to think about this and to
    understand it all.
    Neither english nor ruby are my native languages and im still
    learning. Especially all about databases drives me crazy in regular.
    It took me about 3 hours this morning to get a "simple" has_many up
    and running. Migrating a thousand times or so back and forth.

    I never know where to put the belongs_to and where the has_many, or
    how to set up the migrations, where to use singular and where plural.
    I suggest that you work through some of the Rails Guides, start with
    Getting Started and Active Record Associations. Also the one on
    debugging will come in handy. Then work right through a good tutorial
    such as railstutorial.org, which is free to use online. Then you
    should have a better grasp of the fundamentals of Rails.

    Colin

    --
    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@googlegroups.com.
    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.
  • Tom at Nov 14, 2011 at 10:52 pm
    it seems that u have 2 goals in mind
    a) recipes
    b) ingredients

    since a dish consists of ingredients b and b itself of many b u should look
    into simple treebased appraoch:

    ingredient:
    -id
    -parent_id
    -name
    -uom (=unit of measure)
    -qty (=quantity)





    On Mon, Nov 14, 2011 at 3:14 PM, Colin Law wrote:
    On 14 November 2011 17:51, Norbert Melzer wrote:

    I hope I will have some time this week to think about this and to
    understand it all.
    Neither english nor ruby are my native languages and im still
    learning. Especially all about databases drives me crazy in regular.
    It took me about 3 hours this morning to get a "simple" has_many up
    and running. Migrating a thousand times or so back and forth.

    I never know where to put the belongs_to and where the has_many, or
    how to set up the migrations, where to use singular and where plural.
    I suggest that you work through some of the Rails Guides, start with
    Getting Started and Active Record Associations. Also the one on
    debugging will come in handy. Then work right through a good tutorial
    such as railstutorial.org, which is free to use online. Then you
    should have a better grasp of the fundamentals of Rails.

    Colin

    --
    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@googlegroups.com.
    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.
    --
    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@googlegroups.com.
    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.
  • Norbert Melzer at Nov 15, 2011 at 8:05 pm

    2011/11/14 tom <tomabroad@gmail.com>:

    ingredient:
    -id
    -parent_id
    -name
    -uom (=unit of measure)
    -qty (=quantity)
    With this approach I could use water and flour only to produce Dough.

    But I want to use the water in another recipe to brew a beer and there
    fore I need other qantities. So I think the approach of Frederick
    seems to fit my needs more

    --
    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@googlegroups.com.
    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.
  • Tom at Nov 15, 2011 at 10:02 pm
    no.
    imagine u go from the top, and the deeper u traverse into the tree, the
    more details u get. its secondary if the tree reflects ingredients,
    recipes, or a dish.
    as soon something is made up of something else, your best bet is a tree.
    but, as usual, doing by learning
    good luck

    On Tue, Nov 15, 2011 at 3:05 PM, Norbert Melzer wrote:

    2011/11/14 tom <tomabroad@gmail.com>:
    ingredient:
    -id
    -parent_id
    -name
    -uom (=unit of measure)
    -qty (=quantity)
    With this approach I could use water and flour only to produce Dough.

    But I want to use the water in another recipe to brew a beer and there
    fore I need other qantities. So I think the approach of Frederick
    seems to fit my needs more

    --
    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@googlegroups.com.
    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.
    --
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 13, '11 at 6:14p
activeNov 15, '11 at 10:02p
posts7
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase