Hi Michael

On Apr 20, 1:11 am, Michael Kebbekus <[email protected]> wrote:
> Isn't this supposed to be a more efficient way of saying
> Membership.all(:project_id => []).map(&:user) which returns []?

Yes it is. I don't know how your relationships are set up exactly, but
the following example works for me:

class Project
  include DataMapper::Resource

  property :id,      Serial

  has n, :memberships
  has n, :users, :through => :memberships
end

class Membership
  include DataMapper::Resource

  belongs_to :project, :key => true
  belongs_to :user,    :key => true
end

class User
  include DataMapper::Resource

  property :id, Serial

  has n, :memberships
  has n, :projects, :through => :memberships, :via => :project
end

DataMapper.finalize
DataMapper.auto_migrate!

project = Project.create
user    = User.create

project.users << user
project.save

# you can grab users either via project:
Project.all(:id => [project.id]).users

# or membership
Membership.all(:project_id => [project.id]).user

Hope this helps

Cheers!

# solnic

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" 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/datamapper?hl=en.

Reply via email to