Save data in associated table


#1

Hello
i appreciate it if anyone could help me.
i have a controller named PostsController and and i want each post to be able to have many comments so i set associations in PostsTable : hasmany

association in CommentsTable: belongsTo

i am able to display the comments in a view from PostsController but i failed saving comments from that view in PostsController in the database. i mean i do’nt know how to save data in associated table of comments in database.
i appreciate it if anyone could help me.
Thank you


#2

Posts and Comments normally has belongsToMany association. It means you need a join table for that.
https://book.cakephp.org/3.0/en/orm/associations.html
Saving is described here: https://book.cakephp.org/3.0/en/orm/saving-data.html