0

I am trying do a find statement to get the content accordingly

users(id, name, city_id)
visitors(id, user_id, visitor_id) // visitor_id also refers to users table
cities(id, name)

PHP

    $visitor_data = $this->User->Visitor->find('all', array(
            'conditions' => array('user_id' => 1), 
            'limit' => 10, 
            'order' => array('timestamp DESC'), 
            'contain' => array('VisitorDetails' => array(
                                                    'fields' => array('id', 'first_name', 'last_name', 'username', 'city_id'),
                                                    'contain' => array('City'))
                                                    )
            ));

I am getting an error:

SQL Error: 1054: Unknown column 'VisitorDetails.contain' in 'field list'

I want to get the Visitor Details City information

Harsha M V
  • 54,075
  • 125
  • 354
  • 529

2 Answers2

2

VisitorDetails should be singular :

'contain' => array('VisitorDetail' .....

Ross
  • 18,117
  • 7
  • 44
  • 64
Andras
  • 202
  • 3
  • 6
2
<?php  $visitor_data = $this->User->Visitor->find('all', array(
            'conditions' => array(
                'user_id' => 1
            ), 
            'limit' => 10,
            'order' => array(
                'timestamp DESC'
            ), 
            'contain' => array(
                'VisitorDetail' => array(
                    'fields' => array(
                        'id',
                        'first_name',
                        'last_name',
                        'username',
                        'city_id'
                    ),
                    'contain' => array(
                        'City'
                    )
                )
              )
            ));
?>
jwg2s
  • 806
  • 1
  • 12
  • 25
  • It's best to keep your code in an organized structure so that other programmers can easily/quickly interpret it. – jwg2s Dec 01 '11 at 15:51