Hey sonlic, That looks about right as per our setup, but what happens when you do Membership.all(:project_id => []).user with an empty array?
I'm suggesting that I've found a bug, because I get back the whole user table even though Memberhip.all(:project_id => []) correctly returns an empty Datamapper::Collection. >> Membership.all(:project_id => []) => [] >> Membership.all(:project_id => []).class => DataMapper::Collection >> Membership.all(:project_id => []).user #returns every User!?!? On Apr 20, 12:10 am, Piotr Solnica <[email protected]> wrote: > 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.
