Dear all

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")

>> pat.pat_encounter_group
=> 99999

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.
    def find_request_by_pat_encounter_group
      SX1::Request.find_all_by_req_encounter_group(self.pat_encounter_group)
    end

My question, is it possible to do this in has_many relationship? Thank
you.

module SX9
  class Patient < RemoteSX9Model
    set_table_name "patient"
    set_primary_key "pat_encounter"

    # I tried this but failed
    has_many :requests, :class_name => "SX1::Request", :primary_key =>
"pat_encounter_group", :foreign_key => "req_encounter_group"
  end
end

module SX1
  class Request < RemoteSX1Model
    set_table_name "request"
    set_primary_key "req_reqno"
  end
end

Thank you very much
Valentino
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to