cakephp 1.3是否存在($ id)函数,以查看表中是否存在记录?我有一个从另一台服务器同步的数据库.我的数据库有2个表,同步表,以及我已经放入同步表扩展的表.我的应用程序现在列出主(同步)表中的所有项目,当他们单击该项目时,它会将它们带到视图以添加与第二个表格不同的信息.它将ID传递给第二个表.
我想要做的是先检查第二个表,查看是否存在具有相应外键的记录,如果存在,则转到第二个表中该记录的编辑屏幕,如果没有,我想确定记录存在于第一个表中,如果存在,则将记录添加到第二个表中,并将给定的$ id作为外键.
现在考虑它,它将正确的id传递给第二个表,我只是不希望用户能够键入一个数字并假设它存在于主表中并将记录添加到第二个表中,这不会实际存在.如果没有检查的功能,我可以使用该关联进行检查吗?喜欢:
if (!$this->Table2->Table1->id) {
//if id does not exist in parent table don't create the record in the second table and print an error
} else {
//id does exist in parent table either add a new record with the foreign key being the id passed from parent or redirect to edit screen for that record in second table
}
Run Code Online (Sandbox Code Playgroud)