When I do this I obtain nil:
current_shipment = current_entry.shipment
The models look like this:
class CaCustomsShipment < ActiveRecord::Base
has_one :ca_customs_entry has_one :entry, :class_name => 'CaCustomsEntry' #short form
def to_param shipment_identifier end
class CaCustomsEntry < ActiveRecord::Base
belongs_to :ca_customs_shipment belongs_to :shipment, :class_name => 'CaCustomsShipment'
def to_param cctn end
If I fetch the rows individually via .first then I see this:
--- !ruby/object:CaCustomsEntry attributes: . . . created_at: 2011-02-22 16:40:49.085782 . . . ca_customs_shipment_id: "111"
and
--- !ruby/object:CaCustomsShipment attributes: . . . lock_version: "0" id: "111" . . .
However, If I do this:
puts( CaCustomsShipment.first.entry.to_yaml ) puts( CaCustomsEntry.first.shipment.to_yaml )
The first puts displays the entry I expect but the second returns nil. I also discovered that this fails:
CaCustomsShipment( CaCustomsEntry.first.ca_customs_shipment_id )
but this succeeds
CaCustomsShipment.find_by_id( CaCustomsEntry.first.ca_customs_shipment_id )
This gave rise to the thought that perhaps I was handling the to_param methods incorrectly. I tried removing the to_param definitions from the respective models but the program behaviour does not appear to change.
Clearly I am missing something or other in the association method call but I cannot seem to find what that something is.
Does anyone here see what I am doing wrong?