lpgauth-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Mar-31 00:23 UTC
database design help
Hi, I''m coding a little application to make couples profile. The problem is I just don''t know how to create my databases so that their are no bottlenecks and that I can have a relation. The way I see it is that their would be a user database and a profile database and they would link 2 to 1. Is this the right way? In the user db I would store their userid and some session info, should I use their userid as primary key? DB Scheme User1--- |---Profile User2--- User DB -userid (primary key?) -profileid -session info -timestamp Profile DB -personnal info Any help would be appreciated, thanks'' in advance. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rails'' convention is that every ActiveRecord object is identified by an ''id'' column (auto-incrementing, int primary key) and foreign keys are named <other_table>_id. The nice thing about following the conventions is that it greatly simplifies your coding (in some cases eliminating code!). So your model would look something like this: create_table :users do |t| t.integer :profile_id t.string :crypted_password ... etc ... end class User < ActiveRecord::Base belongs_to :profile end create_table :profiles do |t| ... personal info ... end class Profile < ActiveRecord::Base has_many :users end With those migrations and classes you do not need to specify the name of the primary key (assumed to be id... and written into the create_table migration for you). You also don''t need to tell the has_many macro the name of the foreign key to use when looking up users (or the User objects which Profile to file) since it''s assumed to be profile_id. On Mar 30, 8:23 pm, "lpga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <lpga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, I''m coding a little application to make couples profile. The > problem is I just don''t know how to create my databases so that their > are no bottlenecks and that I can have a relation. The way I see it is > that their would be a user database and a profile database and they > would link 2 to 1. Is this the right way? In the user db I would store > their userid and some session info, should I use their userid as > primary key? > > DB Scheme > User1--- > |---Profile > User2--- > > User DB > -userid (primary key?) > -profileid > -session info > -timestamp > > Profile DB > -personnal info > > Any help would be appreciated, > thanks'' in advance.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---