0

I have models Trip, Investment, and Person. A single trip hasMany investments, and every investment belongsTo one Person. When I say $this->Trip->find('all'); I get:

Array (
    [0] => Array (
            [Trip] => Array (                  
                    [id] => 1
                    [date] => 2012-10-25 13:00:00
                )
            [Investments] => Array (
                    [0] => Array (
                            [id] => 1
                            [person_id] => 1
                            [investment_type_id] => 2
                            [trip_id] => 1
                            [investment] => 55
                        )
                    [1] => Array (
                            [id] => 2
                            [person_id] => 2
                            [investment_type_id] => 1
                            [trip_id] => 1
                            [investment] => 40
                        )
                )            
        )
)

I would like each investment to include the information about the person represented by person_id (So their id, their name, etc). I've tried all levels of recursion on the find('all') lookup with no luck.

tereško
  • 58,060
  • 25
  • 98
  • 150
backus
  • 4,076
  • 5
  • 28
  • 30

2 Answers2

0

have you defined both ways of association in all models?

eg. Trip hasMany Investments AND Investment belongsTo Trip

Investment belongsTo Person AND Person hasMany Investments also query should be

$this->Trip->find->("all", array("recursive" => 2));

other thing what could be problem is if all necessary models are loaded in your controller

Drobek
  • 90
  • 1
  • 7
0

See cakePHP model associations (retrieving data deeper) for an alternative solution: Use

$this->YourModelname->recursive = 3;

before querying.

Community
  • 1
  • 1