Cakephp 3.0 Save associated model
Conventions, conventions, conventions
There's clearly a difference in the examples that you've linked, take a closer look at the property names, and if you scroll down a little further, you'll find an explanation specifically for belogsTo
associations.
When saving belongsTo associations, the ORM expects a single nested entity at the singular, underscored version of the association name. For example: [...]
Cookbook > Saving Data > Saving BelongsTo Associations
So for belongsTo
associations, the property name is by default expected to be lowercased and underscored, ie $aClient->client_preference
.
Your foreign key should btw. be singular too in order to match the conventions, ie client_preference_id
, even though it's just the property name causing the problem.
See also Cookbook > Associations > BelongsTo Associations (especially the foreignKey
and propertyName
options)