Answer the question
In order to leave comments, you need to log in
Rails - association with custom foreign_key not working?
When I try to load the association, the model id is not passed to SQL, but is passed:
jruby-1.7.11 :081 > u.user_privileges
UserPrivilege Load (61.0ms)
SELECT "A_USERPRIVILEGES".* FROM "A_USERPRIVILEGES"
WHERE "A_USERPRIVILEGES"."ID_A_USERS" = :a1 =>
#<ActiveRecord::Associations::CollectionProxy []>
class User < ActiveRecord::Base
self.table_name = 'A_USERS'
self.primary_key = 'ID'
has_many :user_privileges, foreign_key: 'ID_A_USERS',
primary_key: 'ID' # when i remove primary key here then nothing changing
end
class UserPrivilege < ActiveRecord::Base
self.table_name = 'A_USERPRIVILEGES'
self.primary_key = 'ID'
belongs_to :user, foreign_key: 'ID_A_USERS',
primary_key: 'ID' # when i remove primary key here then nothing changing
alias_attribute :user_id, :id_a_users # does not work too
end
A_USERS:
ID NUMBER(38,0)
A_USERPRIVILEGES:
ID NUMBER(38,0)
ID_A_USERS NUMBER(38,0)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question