Sqlite and Rails

Posted by joe Monday, July 31, 2006 08:56:00 GMT

I have enjoyed working with Sqlite ever since Aslak pointed me to it at RubyCon last year. I like having everything inside the same application when I run. All I have to do is checkout the source, run migrate and I’m off

There is, however, a bug on Mac OSX with Sqlite3 that I thought I should help point out – thanks to ruy.asan on the Rails Wiki for pointing out the solution.

The bug exists when you create or save an object in Active Record. The id field gets set to zero instead of the actual value:

 objo:08:55 ~/somewhere > script/console
 >> u = User.create :name => 'alex'
 =>  ... User:0x2 ... 
 >> u.id
 => 0

Turns out that you need to install Swig BEFORE you install the sqlite bindings. I installed swig using ports and then reinstalled the sqlite3-ruby gem. It seems to have taken care of the problem:

 objo:08:55 ~/somewhere > script/console
 >> u = User.create :name => 'alex'
 =>  ... User:0x2 ... 
 >> u.id
 => 7