Hi all, I''ve just discovered Rails coming from an asp.net background. I''m really into rails and I have started to develop an application to manage product data (specs, marketing info, etc). I am having some trouble designing the database to fit into the MVC paradigm and I was hoping someone might have a suggestion for me. Here is my problem: Let''s say I have one table with generic product model info in it: Product Table: modelnum: upc: type: refrigerator, range, etc price: I also need a specs table. The catch is every product type has a different set of spec attributes. How do i design my database without having a huge spec''s table full of unused colums, and logic in the view to display the appropriate spec fields. I thought of perhaps using a table for each product type, but how would you make this association in the model without doing the following: class Product < ActiveRecord::Base has_one :spec_type1 has_one :spec_type2 has_one :spec_type3 has_one :spec_type4 or generating sql strings to pull data from the correct table (which is something I would have probably done in asp)? Alternativly I thought of representing specs with two tables. Specs_def would define all of the available specifications available, and encode each spec_attribute with a spec_type code. A second table would contain all of the spec entries, creating a list of spec_attribute/value pairs linked to the product by product_id. This also seems wrong, and messy when dealing with creating and updating product information. I''m sure there is a better way. Any ideas would be greatly appreciated. Yanir --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I think I found the answer: polymorphic associations. On Mar 10, 12:32 pm, Yanir <yhirshb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, I''ve just discovered Rails coming from an asp.net background. > I''m really into rails and I have started to develop an application to > manage product data (specs, marketing info, etc). I am having some > trouble designing the database to fit into the MVC paradigm and I was > hoping someone might have a suggestion for me. > > Here is my problem: > > Let''s say I have one table with generic product model info in it: > Product Table: > modelnum: > upc: > type: refrigerator, range, etc > price: > > I also need a specs table. The catch is every product type has a > different set of spec attributes. > > How do i design my database without having a huge spec''s table full of > unused colums, and logic in the view to display the appropriate spec > fields. > > I thought of perhaps using a table for each product type, but how > would you make this association in the model without doing the > following: > > class Product < ActiveRecord::Base > has_one :spec_type1 > has_one :spec_type2 > has_one :spec_type3 > has_one :spec_type4 > > or generating sql strings to pull data from the correct table (which > is something I would have probably done in asp)? > > Alternativly I thought of representing specs with two tables. > Specs_def would define all of the available specifications available, > and encode each spec_attribute with a spec_type code. A second table > would contain all of the spec entries, creating a list of > spec_attribute/value pairs linked to the product by product_id. > > This also seems wrong, and messy when dealing with creating and > updating product information. > I''m sure there is a better way. > > Any ideas would be greatly appreciated. > > Yanir--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Sounds right. On Mar 10, 1:03 pm, Yanir <yhirshb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I think I found the answer: polymorphic associations. > > On Mar 10, 12:32 pm, Yanir <yhirshb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi all, I''ve just discovered Rails coming from an asp.net background. > > I''m really into rails and I have started to develop an application to > > manage product data (specs, marketing info, etc). I am having some > > trouble designing the database to fit into the MVC paradigm and I was > > hoping someone might have a suggestion for me. > > > Here is my problem: > > > Let''s say I have one table with generic product model info in it: > > Product Table: > > modelnum: > > upc: > > type: refrigerator, range, etc > > price: > > > I also need a specs table. The catch is every product type has a > > different set of spec attributes. > > > How do i design my database without having a huge spec''s table full of > > unused colums, and logic in the view to display the appropriate spec > > fields. > > > I thought of perhaps using a table for each product type, but how > > would you make this association in the model without doing the > > following: > > > class Product < ActiveRecord::Base > > has_one :spec_type1 > > has_one :spec_type2 > > has_one :spec_type3 > > has_one :spec_type4 > > > or generating sql strings to pull data from the correct table (which > > is something I would have probably done in asp)? > > > Alternativly I thought of representing specs with two tables. > > Specs_def would define all of the available specifications available, > > and encode each spec_attribute with a spec_type code. A second table > > would contain all of the spec entries, creating a list of > > spec_attribute/value pairs linked to the product by product_id. > > > This also seems wrong, and messy when dealing with creating and > > updating product information. > > I''m sure there is a better way. > > > Any ideas would be greatly appreciated. > > > Yanir--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 10, 11:32 am, Yanir <yhirshb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, I''ve just discovered Rails coming from an asp.net background.Welcome! I co-write a blog for people just like us: www.softiesonrails.com. You may (or may not) find it helpful as you learn Rails. Jeff --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---