Writing Custom Model Functions - SQL Error 1054

1 message Options
Embed this post
Permalink
Barry Sampson

Writing Custom Model Functions - SQL Error 1054

Reply Threaded More More options
Print post
Permalink
Hi,

I'm working my way through Beginning CakePHP (and loving it!), but I've hit a problem that I can't find a solution to anywhere else.

I'm working through chapter 7, writing custom model functions, and I've added the necessary code to post.php, posts_controller.php and read.ctp but I have an error that I can't track down. (I have used the amended code available from this forum and other sources).

The error I get is:

SQL Error: 1054: Unknown column 'Post.year' in 'where clause'

This is the query (and you can clearly see the error)

SELECT `Post`.`id`, `Post`.`name`, `Post`.`date`, `Post`.`content`, `Post`.`user_id`, `User`.`id`, `User`.`name`, `User`.`email`, `User`.`firstname`, `User`.`lastname` FROM `posts` AS `Post` LEFT JOIN `users` AS `User` ON (`Post`.`user_id` = `User`.`id`) WHERE `Post`.`year` = '2009' LIMIT 1

I've checked and double checked my code, deleted it and retyped it (again making sure I use the updated code from the Apress errata page), but I cannot see where my error is. Any help would be very much appreciated!

Thanks

Barry