If I am going to build a sql database for use in rails (rather than building it in rails), is there anything I need to know beyond using an id column in every table? Does the id need to be the "primary key"? -- Posted via http://www.ruby-forum.com/.
Yes, the id needs to be the primary key. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Thu, May 21, 2009 at 3:20 PM, Mk 27 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > If I am going to build a sql database for use in rails (rather than > building it in rails), is there anything I need to know beyond using an > id column in every table? Does the id need to be the "primary key"? > -- > Posted via http://www.ruby-forum.com/. > > > >
The id should be an auto-incrementing primary key. Also, column names should be lower cased using an underscore to separate words, i.e. first_name You should also consider adding "created_at" and "updated_at" datetime fields to handle timestamps. Table names should be pluralized. On May 21, 11:20 am, Mk 27 <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> If I am going to build a sql database for use in rails (rather than > building it in rails), is there anything I need to know beyond using an > id column in every table? Does the id need to be the "primary key"? > -- > Posted viahttp://www.ruby-forum.com/.
Mk 27 wrote:> If I am going to build a sql database for use in rails (rather than > building it in rails), is there anything I need to know beyond using an > id column in every table? Does the id need to be the "primary key"?By convention, rails would look for an id as a primary key for all tables. Also, if you use rails migrations to generate the tables, you can say - create_table(:table_name, :id => false) if you don''t want id. This might be required in case your table is from a legacy system. Thanks -- Posted via http://www.ruby-forum.com/.
E. Litwin wrote:> The id should be an auto-incrementing primary key. > Also, column names should be lower cased using an underscore to > separate words, i.e. first_name > You should also consider adding "created_at" and "updated_at" datetime > fields to handle timestamps. > > Table names should be pluralized.Thanks. I just realized I confused this post with one I forgot writing yesterday. This looks like the info I need. -- Posted via http://www.ruby-forum.com/.
Mk 27 wrote:> If I am going to build a sql database for use in rails (rather than > building it in rails),[...] Why would you do that? I understand the use case of a preexisting "legacy" DB, but if you''re building a DB from scratch for use with a Rails app, then it''s just more efficient to use the DB tools that Rails provides. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
> Does the id need to be the "primary key"?You can set your own primary key like def self.up create_table :table_name, :primary_key => :primary_key_field_name, do |t| t.integer :primary_key_field_name --------- end Sijo -- Posted via http://www.ruby-forum.com/.