2

i use this variable to find the comments that related with articles..

 $comment = $this->Article->Comment->findAllById($id);

i get errors when i added conditons like this..

  $comment = $this->Article->Comment->findAllById($id,array('conditions' => array('Comment.status' => 1)));

i see this error>>

Warning (512): SQL Error: 1054: Unknown column 'Comment.' in 'field list' [CORE\cake\libs\model\datasources\dbo_source.php, line 684]
Query: SELECT DISTINCT `Comment`.`` FROM `comments` AS `Comment` LEFT JOIN `articles` AS `Article` ON (`Comment`.`article_id` = `Article`.`id`) WHERE `Comment`.`id` = 15 
tereško
  • 58,060
  • 25
  • 98
  • 150
user1080247
  • 1,076
  • 4
  • 21
  • 51

1 Answers1

2

Take a look at the manual for the findAllBy<field_name>() method.

You'll notice the second parameter is an array of fields.

I would recommend using Cake's standard find method, something like:

$comment = $this->Article->Comment->find('all', array(
  'conditions' => array(
    'Comment.id'     => $id,
    'Comment.status' => 1
  )
));
Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
Moz Morris
  • 6,681
  • 2
  • 20
  • 18