I have a problem with my project; when creating Rails is assigning 1 as
the ID to any instance when it is saved as a record, instead of
assigning the id from the database (though records in the database are
assigned the correct ID).
I have done some digging; in ActiveRecord::Base there is a method
create, which calls insert on the connection object, assigning to id the
returned value.
def create
# ...
self.id = connection.insert(statement, "#{self.class.name}
Create",
self.class.primary_key, self.id, self.class.sequence_name)
Up to this point, id is nil, however, for some reason it is getting set
to 1 by connection.insert, instead of the new id set when the record is
saved.
Following this through, this looks to be an issue with the JDBC adapter.
ActiveRecord::ConnectionAdapters::JdbcAdapter has a method _execute,
which invokes execute(sql) on an instance of
AtiveRecord::ConnectionAdapters::PostgresJdbcConnection , but I cannot
find where that is defined, and I suspect that that is where the problem
is.
I am making steps towards Rails 3, and it maybe that updating gems has
introduced this problem. It was working fine until recently, and I do
not think the recent changes I have made will have had an effect.
However, I am now at a loss as to how to proceed.
Has anyone else experienced this issue? Any ideas anyone?
Using
JRuby 1.6.7 (Ruby 1.9)
PostgreSQL 8.4
Rails 2.3.14
activerecord-jdbc-adapter 1.2.2
jdbc-postgres 9.1.901