Belongs_to association not connected to FK attribute?

Greetings all.

I’m having problems with a belongs_to not reporting the correct info.

p = Patient.new
=> #<Patient:0x26284e0 @new_record=true, @attributes=
{“work_phone”=>nil, “city”=>nil, “postal_code”=>nil, “ACRES”=>nil,
“health_insurance_province_id”=>nil, “province_id”=>nil,
“country_id”=>nil, “address_two”=>nil, “firstname”=>nil,
“lastname”=>nil, “health_insurance_expiry”=>nil,
“health_insurance_version”=>nil, “id_orig”=>0, “PROVIDNUM”=>nil,
“work_extension”=>nil, “sex”=>nil, “health_insurance_number”=>nil,
“home_phone”=>nil, “PROVIDNAME”=>nil, “date_of_birth”=>nil,
“middle_initial”=>nil, “other_phone”=>nil, “address_one”=>nil,
“health_insurance_prov”=>nil}>

p.country_id = 100 #honduras
=> 100

p.country
=> #<Country:0x25a99d8 @attributes={“name_short”=>nil,
“priority”=>“0”, “name_long”=>“Honduras”, “id”=>“100”}>

p.country_id = 105 #Indonesia
=> 105

p.country
=> #<Country:0x25a99d8 @attributes={“name_short”=>nil,
“priority”=>“0”, “name_long”=>“Honduras”, “id”=>“100”}>

p.country_id
=> 105

wtf? why is Honduras returned as p.country? not honduras?

class Patient < ActiveRecord::Base

belongs_to :country

I’m not aware of anything else that should impact the above symptom.
Any ideas rails riders?

It somehow seems that the relationship Country isn’t related to the
attribute “country_id” ??

rails --version 1.1.6

cheers,
Jodi

Associations are cached. If after setting country_id to 105 you do
p.country(true) then you should get the country you expect back

Fed==red

On 7-Nov-06, at 6:09 PM, Fred wrote:

Associations are cached. If after setting country_id to 105 you do
p.country(true) then you should get the country you expect back

Fed==red

wow - learn something new every day. every-single-day

Without much thought it seems to make sense that assigning a value to
the FK really should suggest a cache clear on that association.

Thanx for your help Fred.

J

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs