I have a rails model which is set up like this:
Poi:
id : int
name : varchar
subtype : int
I recently migrated a lot of records from one database to another using mysql_dump and import. The migration seemed to have gone well, and if I query an id in the console it finds that records. There is a record like this:
id : 33
name : testpoi
subtype : 172
If I try to find it using:
Poi.where(:subtype => 172).first
it always returns nil
If I run this exact query on the system from which I migrated the database it does work.
If I run Poi.find(33)
it finds it too. I've tried
Poi.where(:subtype => "172").first
as well to make sure its not a datatype mismatch, but to no avail.
Also, if I add this object to a collection
@otherobject.poilist << Poi.find(33) #=> which has a has many with foreign key subtype
it works just fine (returns true after saving), but if I then restart the production console the association no longer exists, even though the subtype id matches the id of the containing object.
Thanks guys for the replies. It turned out that due to some funky migrations the subtype field was indeed a string. The real miracle here is that in some cases it DID work, because it shouldn't have. Case closed!