当我阅读 J.Gilmore Zend 书籍(模型部分)时:
class Game extends Zend_Db_Table_Abstract
{
protected $_primary='id'; //line 4
}
[..]Line 4 identifies the table's primary key.By default the framework will
presume the primary key is an automatically incrementing integer named id,so
this line is not necessary [..]
我有一个问题:
- 建表时需要手动设置主外键吗 (例如,在 phpmyadmin 中,带有“主键(id),外键(post)引用用户(id)”之类的内容 关于删除级联”)?
- 或者我可以仅通过使用 $_primary、$_dependentTable、$_referenceMap 等引用 Zend 代码来处理表关系和字段性质?
谢谢
卢卡
最佳答案
两者都有。尽管您可以使用 ORM 处理关系,但数据库确保在低级别尊重这些关系。始终让数据库尽可能地完成其工作,它是为处理关系和防止数据损坏而构建的。如果您的 ORM 有错误怎么办?
作为一个有点相关的示例,假设您在数据库中有一个声明为 int 的字段,作为开发人员,您有责任确保在查询中使用 int,但数据库在较低级别强制执行该规则,从而保护您的数据如果你不这样做。关于php - Zend_Db。建数据库表时需要手动设置主键和外键吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6069105/