I know my problem is a question which has been asked already quite often, but the answers given didnt help me, unfortunately.
Currently I just set up an example database for understanding. I have 2 tables users and phone_Numbers.
The UsersModel has a hasMany association with PhoneNumbers and PhoneNumbers a belongsTo association with the UsersModel.
In my Users\add.ctp I created a form for saving data in both tables and simply added
When typing the data into my form, only the datas for the users table are saved but not the one for phone_numbers.
Making use of the debug function I noticed an error in the field user_id, which is the foreignKey in my phone_numbers table:
The difference between patchEntity() and save() is that you use patchEntity() to start building up an entity. This entity will only exist in your computer’s memory until you successfully use save() to persist it to the database.
first of all thank u very much for ur reply. I had tried it the way u suggested and as it is also documented in the cookbook. But it doesnt make any difference. Debugging it, the error is still the same:
[[errors]] => Array
[user_id] => Array
[_required] => This field is required
Yesterday, I came across a similar question on github from 2014 https://github.com/cakephp/cakephp/issues/5292
I tried to do it the same way with hidden inputs, but received a saved error. But Im also new to Cakephp and not very much familiar with hidden inputs (just read about it in the documentation), so maybe I handled it the wrong way. Do u know more about hidden inputs?