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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <davidwrigh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On 7 January 2012 21:12, davidwright66 <davidwright66-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 7 January 2012 21:12, davidwright66 <davidwrigh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.