Welcome Guest, Not a member yet? Register   Sign In
DataMapper - Counting related items
#11

[eluser]phobeous[/eluser]
Hi again and thanks for your "fast as light" answer. You're right, servicio is a collection, but I want to run the count only on the related servicios of expediente with id=1.

include_related_count('servicio/adjunto') fails. This is the generated query:

SELECT `expedientes`.*, (SELECT COUNT(*) AS count FROM (`adjuntos`) LEFT OUTER JOIN `expedientes` `expedientes_subquery` ON `expedientes_subquery`.`id` = `adjuntos`.`servicio_id` WHERE `expedientes_subquery`.id = `expedientes`.`id`) AS servicio/adjunto_count FROM (`expedientes`) WHERE `expedientes`.`id` = 1

Because of the alias 'servicio/adjunto_count', but even fixing the alias and executing the query directly on MySQL, the result is wrong. Table 'servicios' is not queried and it tries to relate adjuntos directly with expediente.

I just suggest that it would be nice and cool if, given a proper relationship configuration, DataMapper library could 'translate' this notation:
Code:
$file = new Expediente(1);
$adjuntos_count = $file->servicio->adjunto->count();

into this query:

SELECT COUNT(*) AS `numrows`
FROM (`adjuntos`)
LEFT OUTER JOIN `servicios` servicios ON `servicios`.`id` = `adjuntos`.`servicio_id`
WHERE `servicios`.`expediente_id` = 1

Furthermore, you give this as an option in your first answer to this thread. The relationship scenario for my suggestion is the same as
Code:
$continent->country->person->count();

But, please Harro, take my comment just as a suggestion. DataMapper works perfectly and it's a great library for which me (and thousand of people around the world) will be always pleased to you.

Cheers.


Messages In This Thread
DataMapper - Counting related items - by El Forum - 03-21-2011, 11:58 AM
DataMapper - Counting related items - by El Forum - 03-21-2011, 05:03 PM
DataMapper - Counting related items - by El Forum - 03-21-2011, 06:06 PM
DataMapper - Counting related items - by El Forum - 03-21-2011, 06:18 PM
DataMapper - Counting related items - by El Forum - 03-22-2011, 01:37 AM
DataMapper - Counting related items - by El Forum - 03-22-2011, 03:53 AM
DataMapper - Counting related items - by El Forum - 03-22-2011, 05:45 AM
DataMapper - Counting related items - by El Forum - 03-24-2011, 07:50 AM
DataMapper - Counting related items - by El Forum - 11-22-2012, 12:22 PM
DataMapper - Counting related items - by El Forum - 11-22-2012, 02:03 PM
DataMapper - Counting related items - by El Forum - 11-23-2012, 01:27 AM
DataMapper - Counting related items - by El Forum - 11-23-2012, 03:39 AM
DataMapper - Counting related items - by El Forum - 11-23-2012, 07:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB