0

当我尝试编辑一个条目时..它在数据库中创建了一个重复的条目。

我确保在进入编辑表单时添加了一个隐藏的 id 字段。

餐厅

餐厅属性

餐厅联系方式

这些是我正在使用的模型。

尝试重新初始化 id

$this->餐厅->id = $this->餐厅->id;

奇怪......在数据库中,额外的条目不存在......

但在蛋糕中显示..试图清除缓存..仍在发生

http://harshamv.com/files/screenshots/2010-07-07_1524.png

http://harshamv.com/files/screenshots/2010-07-07_1525.png

我已经在这里发布了代码

http://forum.phpvideotutorials.com/showthread.php?p=81936

这是索引操作http://bin.cakephp.org/view/660872993

这是模型http://bin.cakephp.org/view/1228539627

http://harshamv.com/files/screenshots/2010-07-10_0937.png

SQL 语句http://pastebin.com/EmdXmNeH

餐厅模型http://pastebin.com/W1sLiL7W

4

3 回答 3

1

I got the answer from teknoid from the MIRC.

In my edit view i have only set the Restaurant.id. none of the ids of the related models are set in the view.

By cake's convention we need to have the id of any record from the db u update. so this was creating a duplicate record in the related models.

In the index action since there is a JOIN of related models. it was creating duplicate entries because of repeated entries in the related model

by adding the ids of all the related model records. this solved the problem.

Thanks all for your time. Finally i managed to get it working.

于 2010-07-13T19:53:05.170 回答
1

如果 phpmyadmin 中只显示一条记录,而应用程序中显示多条记录,那么您的关系有问题。

我将首先删除 hasOne 和 belongsTo 并查看。我以前也有过这种情况,而且总是关系不好。

于 2010-07-09T13:51:30.537 回答
0

检查 ID 列是否设置为主键以及 AUTOINCREMENT。如果设置了此项,则无法插入重复的条目。

这个

$this->Restaurant->id = $this->Restaurant->id; 

做笔记。

编辑:

好的,我的错是我没有看到你在数据库条目中说没问题。然后:

  1. 检查 $this->paginate() 是否返回这些重复的条目 - print_r() 它。如果条目在那里重复,那么您正在弄乱模型中的关系。还将调试选项更改为 2 并查看生成了哪些 SQL。

  2. 如果上述检查中的条目是唯一的,那么在显示 $restaurants 的结果时,您在循环中弄乱了一些东西

我认为这更有可能是第一个建议

于 2010-07-09T18:51:13.387 回答