This project is archived and is in readonly mode.

#6782 new
Roland Pallai

3.0.7: the model uses 'id' field even when 'set_primary_key :uid' set

Reported by Roland Pallai | May 15th, 2011 @ 01:37 AM

Rails console:

> Rails.version
=> "3.0.7"
> User.primary_key
=> "uid"
> User.last.uid
=> 54306
> User.last.attributes['id']
=> 54306
=> 3
> User.last.to_key
=> [3]
> User.last.reload
ActiveRecord::RecordNotFound: Couldn't find User with ID=3

 User Load (0.7ms)  SELECT `sql_users`.* FROM `sql_users` WHERE `sql_users`.`uid` = 3 LIMIT 1

As you can see, the User model has an 'id' field too, next to 'uid'. If I comment out the "set_primary_key :uid" on User, reload works as expected. This model works in 2.3.11.

Associations are also affected, not just the reload.

A simple workaround:

class User
  alias_attribute(:id, :uid)

No comments found

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>