I have a two models set up like this:
class User < ActiveRecord::Base
# external_id column in database
end
class UserUpload < ActiveRecord::Base
belongs_to :user, :primary_key => "external_id", :foreign_key => "external_user_id"
end
However, whenever I do
upload = UserUpload.find(id, :include => :user)
The sql that gets emitted is always looking for ID (and using zeros):
select * from users where id in (0,0,0,0 ... 0,0)
Am I doing something wrong, or is there a problem using foreign_keys
in a belongs_to
relationship with include
?