0
votes

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

2

2 Answers

2
votes

VisitorDetails should be singular :

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

2
votes
<?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'
                    )
                )
              )
            ));
?>