I have the following 2 models, with 2 difference data sources. I would
like to create a has_many relation to SX1::Request
pat = SX9::Patient.find(“123456789”)
By default, rails will use the PK(Primary Key) of SX9::Patient then pass
to SX1::Request. e.g.
SELECT * FROM request WHERE (request.req_encounter_group = “123456789”)
What I am expected is to override the primary_key in SX9::Patient
has_many relation with :primary_key => “pat_encounter_group”. i.e.
SELECT * FROM request WHERE (request.req_encounter_group = 99999)
But I failed to do…
Luckily, I can achieve this by defining a instance method. e.g.
My question, is it possible to do this in has_many relationship? Thank
class Patient < RemoteSX9Model
# I tried this but failed has_many :requests, :class_name => "SX1::Request", :primary_key =>
“pat_encounter_group”, :foreign_key => “req_encounter_group”
class Request < RemoteSX1Model
Thank you very much