0

I'm not sure if I'm doing something bad or this is actually the expected behaviour from Cake.

The following is my code:

$tickets = $this->TicketsPrice->Ticket->find('all',array(
    'contain'=> array(                    
        'TicketsType' => array(
                    'conditions' => array(
                        'provider_id' => $provider_id,
                    ),
                ),
            ),
        )
    );

And this is what I get:

Array
(
    [0] => Array
        (
            [Ticket] => Array
                (
                    [id] => 17
                    [name] => Telecabina
                    [tickets_type_id] => 9
                )

            [TicketsType] => Array
                (
                    [id] => 9
                    [provider_id] => 5
                    [name] => Name
                )

        )

    [1] => Array
        (
            [Ticket] => Array
                (
                    [id] => 16
                    [name] => Pase General
                    [tickets_type_id] => 8
                )

            [TicketsType] => Array
                (
                    [id] => 8
                    [provider_id] => 5
                    [name] => Name
                )

        )


    [4] => Array
        (
            [Ticket] => Array
                (
                    [id] => 13
                    [name] => Pase fin de semana
                    [tickets_type_id] => 7
                )

            [TicketsType] => Array
                (
                    [id] => 
                    [provider_id] => 
                    [name] => 
                )

        )

I should not be getting ticket 4 in the array. Instead, since provider_id doesn't match, I get an empty TicketsType array. Is this the expected the result?

capsula
  • 498
  • 1
  • 7
  • 21

1 Answers1

0

I realized that the condition is actually filtering okay, but I'm not sure how to achieve the same filter to the whole array and not just to the sub array of contained model.

I could do it by doing a foreach and checking empty id's, but not sure how to make it directly in the find function, just as you would do it with a where SQL condition.

capsula
  • 498
  • 1
  • 7
  • 21