Foreign table references...a new twist


#1

I thought I was on top of them all, but found another one that has me
completely stumped.

table referral_notes
belongs_to: placement

table placements
has_many: referral_notes

def list_rfn
@placement = Placement.find(:all) # possibly unnecessary
@referral_note = ReferralNote.find(:all,
:include => [:placement],
:conditions => [“placement_id = ?”, params[:placement_id] ])
@referral_note_pages, @referral_notes = paginate(
:referral_notes,
:include => [:placement],
:conditions => [“placement_id = ?”, params[:placement_id] ],
:per_page => 14)
end

list view (possible multiple records). The main object is the
‘placement_id’ (there’s only 1).

If I have a looped structure, I can make this work but it repeats the
placement record 1 time for each referral_note…

<% for referral_note in @referral_notes %>
<%=h (referral_note.placement.client.wholename) %>
<%=h (referral_note.note_date) %>
<% end %>

but if I take the first line out of the loop…

<%=h (referral_note.placement.client.wholename) %>
<% for referral_note in @referral_notes %>
<%=h (referral_note.note_date) %>
<% end %>

it errors - not having a definition for ‘referral_note.’
so I try
<%=h (@referral_note.placement.client.wholename) %>

and I still get error…
NoMethodError in Referral_notes#list_rfn
Showing app/views/referral_notes/list_rfn.rhtml where line #16 raised:

undefined method `placement’ for #Array:0xb7a9d904

Extracted source (around line #16):

16:

<%=h (@referral_note.placement.client.wholename) %>

as if it lacks knowledge of the relationship for ‘placement’

and I have had too many issues working with the ‘many’ relationships of
referral_notes in the placement controller and have settled on the
thinking that relationships are easiest when working in the controller
that ‘belongs_to’ side of the relationship.

how/why does it not understand the relationship placement here?

Craig