CakePHP添加一个belongsTo表没有找到?
我有一个 CakePHP 模型,如下所示(并且工作正常):
class Paper extends AppModel {
var $name = 'Paper';
var $displayField = 'id';
}
由于我的数据库中有一个 papers
表,因此不会出现错误。
当我将模型更改为这样时(我只是添加最后一行):
class Paper extends AppModel {
var $name = 'Paper';
var $displayField = 'id';
var $belongsTo = 'User';
}
我收到错误:
Missing Database Table
Error: Database table ps for model Papers was not found.
Notice: If you want to customize this error message, create app\views\errors\missing_table.ctp
CakePHP 在添加 belongsTo
行时突然假设一些第一个和最后一个字符命名法可能会出现什么问题?
编辑
我可能错了,但错误不应该是model Paper
吗?它说的是论文
。添加 belongsTo
语句后会发生这种情况。这是错误所在吗?
I have a CakePHP model which looks like this (and works fine):
class Paper extends AppModel {
var $name = 'Paper';
var $displayField = 'id';
}
This gives no error since I have a papers
table in my database.
When I change the model to so (I simply add that last line):
class Paper extends AppModel {
var $name = 'Paper';
var $displayField = 'id';
var $belongsTo = 'User';
}
I get the error:
Missing Database Table
Error: Database table ps for model Papers was not found.
Notice: If you want to customize this error message, create app\views\errors\missing_table.ctp
What could be going wrong that CakePHP suddenly assumes some first and last character nomenclature on adding a belongsTo
line?
EDIT
I may be wrong with this, but shouldn't the error say model Paper
? It's saying Papers
instead. This happens after adding the belongsTo
statement. Is this where the error is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法解决了这个问题。
简而言之,模型-模型链接并非CakePHP 文档中所称的单向街道。
例如,如果模型 A
belongsTo
模型 B,则模型 B 必须hasOne
或hasMany
模型 A。在我的例子中,接收端的语法是有缺陷的。
I managed to fix this issue.
Simply put, model-model links are not a one-way street as the CakePHP documentation calls it.
For example if model A
belongsTo
model B, then model B MUSThasOne
orhasMany
model A.In my case, syntax at the receiving end was faulty.