
| Key: |
ACTIVERECORD_JDBC-11
|
| Type: |
Bug
|
| Status: |
Resolved
|
| Resolution: |
Fixed
|
| Priority: |
Major
|
| Assignee: |
Unassigned
|
| Reporter: |
kosnyrev
|
| Votes: |
1
|
| Watchers: |
2
|
|
If you were logged in you would be able to see more operations.
|
|
|
|
Environment:
|
Rails 2.3.2 on jruby 1.2.0
Rails 2.3.2 on jruby 1.2.0
|
|
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
|
|
Description
|
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 |
Show » |
Sort Order:
|
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
.