views:

87

answers:

2

I've got two models that look like this

class Stage
    include DataMapper::Resource
    property :id, Serial
    belongs_to :staff
end

class Staff
  include DataMapper::Resource
  property :id, String, :key => true 
  property  :full_name, String 
  property  :email, String
  has n, :stages
end

I'm trying to find all Stages that have a specific Staff member assigned. I've tried @stages = Stage.all(Stage.Staff => 'TM')

What am I doing wrong?

A: 

I'd do

@stages = Stage.all(:staff => 'TM')
philippe
It does not return an error, but does not return any data either. If I run it on other fields such as title, it works ok, but not for the foreign key?
Tom
@Tom I cannot test it, I'd suggest to try to indicate the association with :links e.g. `Stage.all(:links => [ :staff], Stage.staff.id => 'TM')`
philippe
+1  A: 

Try this, its been a while since i used DataMapper.

Stage.all(Stage.staff.id => 'TM')

This is assuming that the 'TM' would actually be the value you use for the id of the staff member.

Hendrik
Thanks, this worked a treat.
Tom