Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Datamapper - Count related items
#3

[eluser]drakeonfire[/eluser]
Hello WanWizard,

Thanks for the reply - I think it's what I was looking for, however, now I've implemented it, it doesn't seem to allow me to access the normal results (e.g. Title etc). Any ideas?

The query looks like so:
Code:
SELECT (SELECT COUNT(*) AS count
FROM (`products`)
LEFT OUTER JOIN `categories_products`
categories_products ON `products`.`id` = `categories_products`.`product_id`
WHERE
categories_products.category_id = categories.id) AS product_count
FROM (`categories`)
ORDER BY
`categories`.`order` asc, `categories`.`title` asc
The code in the controller is:
Code:
$items = new Category();
$products = $items->product;
$products->select_func('COUNT', '*', 'count');
$products->where_related('category', 'id', '${parent}.id');
$items->select_subquery($products, 'product_count');
$data['items'] = $items->order_by('order asc, title asc')->get();

And I'm trying to access the stuff by doing a foreach loop and then accessing the title by something like $item->title; however that doesn't bring anything out, even though $item->product_count; shows a 0.

Any ideas?

Thanks


Messages In This Thread
[SOLVED] Datamapper - Count related items - by El Forum - 02-14-2012, 12:27 PM
[SOLVED] Datamapper - Count related items - by El Forum - 02-14-2012, 02:24 PM
[SOLVED] Datamapper - Count related items - by El Forum - 02-14-2012, 02:58 PM
[SOLVED] Datamapper - Count related items - by El Forum - 02-14-2012, 02:59 PM
[SOLVED] Datamapper - Count related items - by El Forum - 02-14-2012, 03:54 PM
[SOLVED] Datamapper - Count related items - by El Forum - 02-14-2012, 05:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB