I have a user model which has a users table associated with it. I need to create a relational database around the user table like a user can have many credit cards, a user can have many schemes, a user can know many languages so on and so forth. I have some 7 to 10 association between the user and different models. How should I go about it? 1. Should I create a user table, a credit_card table and a users_credit_cards table and have them in a has_many through relationship. This way I would be creating a reference table for each of the association that is required. I would end up referencing some 15 tables to render a single form. 2. Should I have them in a polymorphic association where I have a user_details table which has a detail_type which can contain the class name of either language,credit card etc. Or do you think that there is a better way to do this task. Any help in this would be highly appreciated. Thanks in advance:) Cheers, Jazzy -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jazzy jazzy wrote:> I have a user model which has a users table associated with it. > I need to create a relational database around the user table like a user > can have many credit cards, a user can have many schemes, a user can > know many languages so on and so forth. I have some 7 to 10 association > between the user and different models. > > How should I go about it? > 1. Should I create a user table, a credit_card table and a > users_credit_cards table and have them in a has_many through > relationship. This way I would be creating a reference table for each of > the association that is required. I would end up referencing some 15 > tables to render a single form. > 2. Should I have them in a polymorphic association where I have a > user_details table which has a detail_type which can contain the class > name of either language,credit card etc. > > Or do you think that there is a better way to do this task. > > Any help in this would be highly appreciated. > Thanks in advance:) > Cheers, > JazzyRegarding the credit cards association, I''d say that a "has_many :through" is probably the best way to go. Say a :user has_many :credit_cards, :through => :account or something. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Every entity can have its own table. Then you can define the relationships between them. The use cases will drive the actual design decisions. You will be able to figure out whether habtm or has many through will satisfy your requirements. I don''t think STI is a good solution for your scenario. On 10/25/07, jazzy jazzy <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have a user model which has a users table associated with it. > I need to create a relational database around the user table like a user > can have ma--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---