Raptrex
Raptrex

Reputation: 4115

CakePHP help with read()

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

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()?

Upvotes: 0

Views: 79

Answers (1)

Paolo Bergantino
Paolo Bergantino

Reputation: 488704

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.

Upvotes: 4

Related Questions