Search code examples
cakephprelationships

cakePHP, model relations - hasOne, how to update both tables?


I have two tables: answers{..., question_id} and questions{..., answer_id}.
In the models I set the $hasOne variable to connect the models: Answers: $hasOne = 'Question' and Question: $hasOne = 'Answers'
There are two views: answers->add and questions->add, for each question there is only one answer.
Now, I want these tables to be connected, so when a user create a question it will automatically create an answer (tho empty). I know it's a lot.. But, How it is done?


Solution

  • Perfect answer, here...

    http://book.cakephp.org/#!/view/1032/Saving-Related-Model-Data-hasOne-hasMany-belongsTo