cakePHP,模型关系 - hasOne,如何更新两个表?
我有两个表:answers{..., Question_id}
和 questions{..., answer_id}
。
在模型中,我设置 $hasOne
变量来连接模型:Answers: $hasOne = 'Question'
和 Question: $hasOne = 'Answers'
有两种视图:answers->add
和 questions->add
,每个问题只有一个答案。
现在,我希望连接这些表,因此当用户创建问题时,它将自动创建答案(尽管为空)。 我知道很多......但是,它是如何完成的?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完美的答案,在这里...
http ://book.cakephp.org/#!/view/1032/Saving-Related-Model-Data-hasOne-hasMany-belongsTo
Perfect answer, here...
http://book.cakephp.org/#!/view/1032/Saving-Related-Model-Data-hasOne-hasMany-belongsTo