Lighthouse has a new layout.
Prefer the old one? Return to the old layout,
and switch back any time from the link at the top of each page.
This project is archived and is in readonly mode.
3.0.7: the model uses 'id' field even when 'set_primary_key :uid' set
#6782
Rails console:
> Rails.version
=> "3.0.7"
> User.primary_key
=> "uid"
> User.last.uid
=> 54306
> User.last.attributes['id']
=> 54306
> User.last.id
=> 3
> User.last.to_key
=> [3]
> User.last.reload
ActiveRecord::RecordNotFound: Couldn't find User with ID=3
[...]
log/development.log:
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)
end
Reported by Roland Pallai ·
May 15th, 2011 @ 01:37 AM