Need help with deciding on the association

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

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,
Jazzy

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs