rails-sqlserver/activerecord-sqlserver-adapter — Issue #160: returned id of created objects is wrong
Author: timsjoberg
Created: 2012-01-30 15:26:04+00:00
State: open

I don't know if this is a peculiarity of the database I'm connecting to, or if it's a bug in the sqlserver adapter, but some insight would be great.

I'm attempting to migrate data from a sqlserver database to a postgres database. The schemas are not the same. In my testing, I'm trying to check that associations are working as expected on the sqlserver models. I'm using activerecord 3.0.11 as associations are broken in activerecord 3.1 when connecting to multiple databases ( https://t.co/FIXFfAnG ). I'm using sqlserver adapter version 3.0.19. This is the behaviour I'm experiencing:

random_string = SecureRandom.hex(16)
country = Host::Country.create!(:Country => random_string)
p country
# => #
p Host::Country.find_by_Country(random_string)
# => #

The model looks something like this (where HostDatabase is an abstract class inheriting from AR::Base and establishing the connection correctly):

module Host
class Country < HostDatabase
set_table_name 'AFW_Countries'
set_primary_key 'CountryID'
end
end

It seems to _always_ give 19 back in this scenario. Is it attempting to use a sequence and not doing it properly? (if this was the case, surely it should be going up?). Or is this a legitimate bug?