1
votes

I have a table called 'Interestslogs' and model's name is Interestlog.

I need to get the client_id according to id from that table in Cakephp.

$client_id = $this->Interestslog->find('first',array(
        'conditions' => array('Interestslogs.id' => $id),
        'fields' => array('Interestslogs.client_id'),
        )
    );

However I am getting database error:

Database Error

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Interestslogs.interest_id' in 'field list'

SQL Query: SELECT Interestslogs.interest_id FROM efa.interestslogs AS Interestslog LEFT JOIN efa.interests AS Interest ON (Interestslog.interest_id = Interest.id) LEFT JOIN efa.clients AS Client ON (Interestslog.client_id = Client.id) WHERE Interestslogs.id = 1 LIMIT 1

4
Check that your Interestslog table contains the field interest_id - thecodeparadox

4 Answers

1
votes

Remove the plural "s" form Interestslogs

$client_id = $this->Interestslog->find('first',array(
    'conditions' => array('Interestslog.id' => $id),
    'fields' => array('Interestslog.client_id'),
    )
);

and also check your model. If every thing (Client and Interestslog) is associated properly you shouldn't get any error.

0
votes

You can try: (if your relations are all right)

$this->Interestslog->recursive = -1;
$client_id = $this->Interestslog->find('first',array(
     'conditions' => array('Interestslogs.id' => $id),
     'fields' => array('Interestslogs.client_id'),
    )
);
0
votes

Check if there is interest_id column in your Interestlogs table.

Or try

$variable_temp = $this->Interestslog->findById($id);
//debug($variable_temp);
$client_id = $variable['client_id'];
0
votes
$client_id = $this->Interestslog->find('first',array(
        'conditions' => array('Interestslog.id' => $id),
        'fields' => array('Interestslog.client_id'),
        )
    );

You should write the table names in the condition/field array without the last "s" since it's added by cakephp automatically.