Reputation: 5860
I have a user table
which contains
the user registration details
such as username
, password
and email
...
How can I add
a profile table
to store
name, country, age etc
... ?
Do I simply create
the table
and use JOIN
to select the data or is there another way to do this
using Ruby on Rails
?
Upvotes: 0
Views: 337
Reputation: 1785
Use a migration to add those columns to the user model. From the sounds of it I don't think you would actually need a separate model for those attributes.
your migration might look something like
rails g migration AddProfileDataToUsers
class AddProfileDataToUsers < ActiveRecord::Migration
change_table :users do |t|
t.add_column :name, :string
t.add_column :country, :string...
#whatever else you want to add to the user model here
end
end
Then you can pull the data as you need it by doing @user.country or something along those lines. Hope this helps
Upvotes: 3