我正在使用 CakePHP v.2.0 和 MySQL。
我有两个模型,即 Candidate 模型和 Lottery 模型,它们通过 HABTM 关系连接。
我想在我的 mysql 数据库中保存这个 HABTM 关系的数据,有两个限制:
1)我没有使用视图,也就是说,我想手动构造作为保存函数中第一个参数传递的数据数组 - 但是它的格式是什么?
2) 没有候选人表,因为我的候选人模型从 LDAP 加载数据(我已按照 http://bakery.cakephp.org/articles/psychic/2009/03/12/ldap-models-in-cakephp)。我只想保存在表lotteries 和连接表candidates_lotteries 中。
任何想法将不胜感激。
I am using CakePHP v.2.0 with MySQL.
I have two models, Candidate and Lottery connected with a HABTM relationship.
I want to make a save of this HABTM relation's data in my mysql db, with two restrictions:
1) I am not using a View, that is, i want to construct manually the data array passed as the first parameter in save function - but what's its format?
2) There is no candidates table, as my Candidate model loads data from LDAP (I’ve followed the tutorial at http://bakery.cakephp.org/articles/psychic/2009/03/12/ldap-models-in-cakephp). I just want to save in table lotteries and in the join table, candidates_lotteries.
Any ideas would be much appreciated.
发布评论
评论(1)
只要您在模型中正确设置了关系,并且您确实拥有 HABTM 表,您就可以简单地执行以下操作:
这应该在 HABTM 表中显示一条新记录。
As long as your relationships are setup correctly in the models, and you do have the HABTM table, you can simply do the following:
This should show a new record in the HABTM table.