Datamapper - return distinct objects from one to many join |
I'm trying to get my head around whether datamapper is the right ORM for me.
I've set up classes Product and Productimage, with a one to many relationship (a product can have many images). When I retrieve a list of products and related images, any product with multiple images is represented multiple times in the result set. Is there any way around this? PHP Code: class Product extends DataMapper { Code: Product : Hammer The database query returns: Code: id name productimage_id productimage_filename productimage_product_id I understand why a join can cause the result set to have many entries for each product, but is it not possible for datamapper to identify that it already has that product's id, and add subsequent rows to that products's productimages collection? I considered using distinct, but the rows are already distinct (as they've got different images on each row). I considered using group by, but that simply removed subsequent result for each product. Any other options I'm not aware of?
This is simply the way one-to-many and many-to-many relationships work in SQL. You may have better luck finding specific options for Datamapper in a forum specific to it, but, lacking any option to change its behavior, your best bet would be to loop through the result set in your model or controller and create a new dataset based on the output you desire.
|
Welcome Guest, Not a member yet? Register Sign In |