I'm new to DataMapper and trying my best to learn and embrace it
instead of resorting to SQL. In this particular situation I have a
model with Menus, Meals and Ingredients. All set up with "has
n, :XXX, :through => Resource".

In one location I want to grab a Menu, and show all ingredients for
all meals in that menu. The problem is if 2 meals reference "1 onion",
for example. In that case DM is generating a join that only provides 1
entry for "1 onion", but I expect two.

I'm using:

@ingredients = Menu.first( :name => 'main').meals.ingredients.all

I'm assuming I need to somehow modify my reference to the meals
collection, but I can't seem to find where the documentation talks
about this. Any pointers?

J.D.

Model for reference:


class Meal
  include DataMapper::Resource

  property :id,     Serial  # autoinc
  <snip>

  has n, :ingredients, :through => Resource
  has n, :menus, :through => Resource
end

class Ingredient
  include DataMapper::Resource

  property :id,       Serial
  property :name,     String
  <snip>

  has n, :meals, :through => Resource
end

class Menu
  include DataMapper::Resource

  property :id,       Serial
  property :name,     String

  has n, :meals, :through => Resource
end

-- 
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