As a work around, this should do the trick, but it requires attributes
that in combination are equivalent (or close) to the id column.
Therefore its a bit iffy.
I’ve been hanging around this problem for a while now, if you want to
point me in the right direction I’ll look at the source and see if I
can do anything about it.
I’m hung up on this same problem, on the same platform, save for the
fact
that I’m using rails 1.1.4 and corresponding versions of its libraries.
I took Travis’ suggestion, but extended it a bit, to make a good effort
to
insure that it returns the desired record: #my class is called Itinerary, and uses the created_at convention,
obviously
def after_create
write_attribute( ‘id’, Itinerary.find( :first, :select => ‘id’,
:conditions => [“name = ? and created_at = ?”, self.name,
self.created_at] ).id
)
end
This works, but it’s pretty ugly, and not 100% safe: what if two users
save
an Itinerary named “Trip to Houston” within one second of each other?
;-p
Q: It seems is that ActiveRecord?s save method doesn?t set the id
of the inserted row after saving the record to a SQLite database.
Is this an issue with SQLite or with ActiveRecord?
A: Make sure you have swig installed before installing sqlite3-
ruby! See the question immediately above this one for instructions.
I?ve had the exact problem and installing swig then re-install
sqlite3-ruby did fix it. One note: I believe sqlite3-ruby is the
preferred module (sudo gem install sqlite3-ruby).
and the relevant bit on installing swig:
On Mac OS X 10.4 Tiger, try uninstalling the gem (sudo gem
uninstall sqlite3), then use DarwinPorts or Fink to install SWIG
(sudo port install swig), making sure SWIG is in your PATH, then re-
install the SQLite3 gem (sudo gem install sqlite3).