Issue Details (XML | Word | Printable)

Key: ACTIVERECORD_JDBC-11
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: kosnyrev
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
activerecord-jdbc

activerecord_jdbc_adapter tries to get new id from sequence, when id specified manualy.

Created: 01/Apr/09 01:13 PM   Updated: 01/Oct/09 09:13 PM   Resolved: 01/Oct/09 09:13 PM
Component/s: PostgreSQL
Affects Version/s: 0.9.1
Fix Version/s: 0.9.2

Time Tracking:
Not Specified

Environment:

Rails 2.3.2 on jruby 1.2.0


Tags:


 Description  « Hide

We need to use non automatic generated ids in our database. Value for primary key is generated manually before saving newly created AR object. Creating new record in database invokes ::JdbcSpec::PostgreSQL.insert method. It tries to get value for primary key from sequence, regardless of the fact that it was already specified. As a workaround we use monkey patch:

::JdbcSpec::PostgreSQL.module_eval do
def insert_with_id(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
if id_value
execute(sql, name)
return id_value
else
insert_without_id(sql, name, pk, id_value, sequence_name)
end
end

alias_method_chain :insert, :id
end



sveiss added a comment - 13/Jul/09 04:48 PM

I'm working on fixing AR test failures with activerecord-jdbc-adapter and PostgreSQL – I'll send a pull request when I get a bit further along – but I think one of my changes should also fix this issue.

The commit which should fix it is at http://github.com/sveiss/activerecord-jdbc-adapter/commit/bb864badf4c7dc205dd3663320977f9a90ce8774 .


Nick Sieger added a comment - 01/Oct/09 09:13 PM

This should be fixed for 0.9.2. Please re-open if not.