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

[eluser]phobeous[/eluser]
Hello, I know it's been long since this thread was last replied, but I'm facing the same issue as first post. My relationships:

expedientes --- 1:N --> servicios --- 1:N --> adjuntos

adjuntos.servicio_id exists
servicios.expediente_id exists

Models are correctly related

Code:
class Expediente extends DataMapper
{
   public $has_many = array('servicio');
   //...
}
//...
class Servicio extends DataMapper
{
   public $has_one = array('expediente');
   public $has_many = array('adjunto');
   //...
}
//...
class Adjunto extends DataMapper
{
   public $has_one = array('servicio');
   //...
}

All my models have $table and $model overriden because inflector on spanish may not work properly. Database has rows on tables that relate items. If I do the count from the last side of the oneToMany relation (adjuntos) it works:
Code:
$adjuntos = new Adjunto();
$adjuntos->where_related('servicio/expediente', 'id', 1);
echo $adjuntos->count(); // Echoes the correct number of related adjuntos for servicios on expediente with id 1.

I will use the working option, but it would be very nice (and cool!) to perform the query this other way:
Code:
$expedientes = new Expediente(1);
$adjuntos_count = $expediente->servicio->adjunto->count();

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