Hi,

I am creating a stock control application.
I have a table called "equipment_type" that stores a general
description of a piece of equipment. This could be for instance: Canon
60D DSLR camera.
I also have an table called "equipment" that stores all the equipment
we have with their serial numbers. There may be many Canon 60Ds and
they should refer to the "equipment_type" table for their description.
Is this a one-to-one association, because they have only one
description.
Or is this a one-to-many, because one "equipment_type" is related to
many "equipment"

Thanks for your help

--
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.

Search Discussions

  • Colin Law at Jan 8, 2012 at 12:16 pm

    On 7 January 2012 21:12, davidwright66 wrote:
    Hi,

    I am creating a stock control application.
    I have a table called "equipment_type" that stores a general
    description of a piece of equipment. This could be for instance: Canon
    60D DSLR camera.
    I also have an table called "equipment" that stores all the equipment
    we have with their serial numbers. There may be many Canon 60Ds and
    they should refer to the "equipment_type" table for their description.
    Is this a one-to-one association, because they have only one
    description.
    Or is this a one-to-many, because one "equipment_type" is related to
    many "equipment"
    If it were one to one then there could only be one equipment object
    for each type, that is what one to one means. Have a look at the
    Rails Guide on ActiveRecord Associations for a good introduction to
    the association types.

    I would avoid the use of the word equipment for the table name. It
    does not read well. Normally the table name should be the plural of
    the objects in the table. equipment_item might be better, then you
    can have one equipment items or two equipment_items.

    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.
  • Davidwright66 at Jan 9, 2012 at 9:23 pm
    Thanks very much for your reply. I now understand it has to be a one-
    to-many relation. Also you are right about the name. It caused me much
    confusion and I have changed it to something that pluralizes much
    better.
    On Jan 8, 12:15 pm, Colin Law wrote:
    On 7 January 2012 21:12, davidwright66 wrote:

    Hi,
    I am creating a stock control application.
    I have a table called "equipment_type" that stores a general
    description of a piece of equipment. This could be for instance: Canon
    60D DSLR camera.
    I also have an table called "equipment" that stores all the equipment
    we have with their serial numbers. There may bemanyCanon 60Ds and
    they should refer to the "equipment_type" table for their description.
    Is this aone-to-oneassociation, because they have onlyone
    description.
    Or is this aone-to-many, becauseone"equipment_type" is related to
    many"equipment"
    If it wereonetoonethen there could only beoneequipment object
    for each type, that is whatonetoonemeans.  Have a look at the
    Rails Guide on ActiveRecord Associations for a good introduction to
    the association types.

    I would avoid the use of the word equipment for the table name.  It
    does not read well.  Normally the table name should be the plural of
    the objects in the table.  equipment_item might be better, then you
    can haveoneequipment items or two equipment_items.

    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.
  • Hangul at Jan 8, 2012 at 8:42 pm
    From my understanding, It is more likely one-to-many relationship
    because, as you already mentioned, one "equipment_type" is referenced
    by many "equipment".

    In Rails perspective, they can be associated like this:
    equipment belongs_to equipment_type
    equipment_type has_many equipment

    Hope it would be help.

    On Jan 7, 4:12 pm, davidwright66 wrote:
    Hi,

    I am creating a stock control application.
    I have a table called "equipment_type" that stores a general
    description of a piece of equipment. This could be for instance: Canon
    60D DSLR camera.
    I also have an table called "equipment" that stores all the equipment
    we have with their serial numbers. There may be many Canon 60Ds and
    they should refer to the "equipment_type" table for their description.
    Is this a one-to-one association, because they have only one
    description.
    Or is this a one-to-many, because one "equipment_type" is related to
    many "equipment"

    Thanks for your help
    --
    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
postedJan 8, '12 at 9:39a
activeJan 9, '12 at 9:23p
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase