tags:

views:

15

answers:

1

I am following the blog tutorial and modifying it to fit my site's needs. I am having a little trouble with my view function.

    function view($id = null)
    {
        $this->Article->articleid = $id;
        $this->set('article', $this->Article->read());
    }   

This line does not work, I get this error: Warning (512): SQL Error: 1054: Unknown column 'Article.id' in 'where clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 681]

However, I got it to work with $this->set('article', $this->Article->find('first' , array('conditions' => array('Article.articleid' => $id))));

My schema for articles is

  • articleid
  • userid
  • title
  • text

The query has WHERE Article.id = '1' however, thats wrong. It should be articleid instead of id

Anyway I can change this so I could use read()?

+4  A: 

Have you specified inside the Article model that var $primaryKey = 'articleid'; ?

From the documentation:

Each table normally has a primary key, id. You may change which field name the model uses as its primary key. This is common when setting CakePHP to use an existing database table.

Paolo Bergantino
Thanks, thats what I was looking for.
Raptrex