Don't forget your primary key

If are you are using a non-standard column name for your primary key (something other than ‘id’), maybe from a legacy database, it is very important not to forget to set the var $primaryKey in your model. This little oversight can break a lot of things without giving any clue as to what the problem is.

A common issue is to have column named ‘ID’ instead of ‘id’, which will cause CakePHP to behave strangely and it’s not very obvious as to what is really going on.

So, if you are having some strange issues with find methods or the data is not comming back as you’d expect, always double-check your primary key name.

Related Posts