Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM - How to get all of a model and each instance's related data
#1

[eluser]coderego[/eluser]
I do not understand how to do the following:

Lets say I have a product table, and a photo table. 1 Product has many photos. So in the product model I do:

Code:
var $has_many = array("category", "photo");
Now I want to get all products and relate each of their photos to them. How can I do this? Currently, in my controller I am going through each of the products and querying photos and passing a separate array that way. This CANNOT be ideal. I should be able to tie each photo to the specific product directly no?

Logically, this would work (but it doesnt?)

Code:
$product = new Product;
$products = $product->get_by_related_category('name', $where);
$photos = $product->photo->get();
See what I'm getting at? I would love to just pass that $products variable to my view, be able to foreach through it, and have an array of photos tied to each product object.

How can I accomplish this? Or is there a better way to do this?

Thanks!


Messages In This Thread
DataMapper ORM - How to get all of a model and each instance's related data - by El Forum - 04-20-2013, 02:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB