Ticket #121 (closed defect: fixed)

Opened 19 months ago

Last modified 13 months ago

example apps say to use :id => false, this is bad form

Reported by: evanweaver Owned by: why
Priority: major Milestone:
Component: examples/blog Version:
Keywords: Cc:

Description

In some cases it also leads to bugs for RDBMS systems that don't take :auto_increment => true nicely.

Is in blog.rb, and possibly others. Has been tripping up the Scots.

Change History

  Changed 19 months ago by why

  • status changed from new to closed

YES.

follow-up: ↓ 3   Changed 19 months ago by evanweaver

  • status changed from closed to reopened

The manual column additions:

t.column :id, :integer,:null => false

need to be excised too. (blog.rb and campsh.rb).

in reply to: ↑ 2   Changed 16 months ago by mikemondragon

Replying to evanweaver:

The manual column additions: t.column :id, :integer,:null => false need to be excised too. (blog.rb and campsh.rb).


This is the hack I have in camping/session.rb line 62 of gem installed Camping 1.5

create_table is defaults to :id => true and the explicit :id column does not need to be explicitly declared.

This makes a Camping app I'm writing happy with the mysql-2.7 and sqlite3-ruby-1.2.1 adapters and AR 1.15.3. I'm on Debian Lenny x86.

    def self.create_schema
        unless table_exists?
            ActiveRecord::Schema.define do
                create_table :sessions, :force => true do |t|
                    t.column :hashid,      :string,  :limit => 32
                    t.column :created_at,  :datetime
                    t.column :ivars,       :text
                end
            end
            reset_column_information
        end
    end

  Changed 13 months ago by zimbatm

Does [205] solve the problem ?

  Changed 13 months ago by zimbatm

  • status changed from reopened to closed
  • resolution set to fixed

Checked on #rubyonrails, werdnativ says that the id is automatically created.

To understand the issue : the automatically incremented :id column definition, highly depends on the RDBMS. For example, MySQL has the non-standard auto_increment attribute. I think, Oracle needs a stored procedure, ... The best way is to let ActiveRecord handle the case. Apparently, it takes the right decision for you :)

Note: See TracTickets for help on using tickets.