CakePHP 架构 shell 或迁移中是否支持外键?

发布于 2024-08-04 23:55:55 字数 592 浏览 1 评论 0原文

我是 CakePHP 的新手,我正在尝试在 之间做出决定CakePHP 附带的 schema shell 以及 乔尔·莫斯格奥尔基·莫姆奇洛夫

到目前为止,我还没有发现它们中的任何一个对创建外键约束有任何直接支持。您似乎可以在迁移中编写原始 SQL 来创建外键。

我错过了什么吗?有地方支持吗?我应该使用外键吗?我看到一些与 CakePHP 或 Ruby on Rails 相关的评论说不鼓励外键约束。我们的数据库仅由一个应用程序使用。

I'm new to CakePHP, and I'm trying to decide between the schema shell that comes with CakePHP and the migrations tools that were written by Joel Moss and Georgi Momchilov.

So far I haven't found any direct support in either of them for creating foreign key constraints. It appears that you might be able to write raw SQL in a migration to create a foreign key.

Have I missed something? Is there support somewhere? Should I even be using foreign keys? I've seen a few comments related to CakePHP or Ruby on Rails saying that foreign key constraints are discouraged. Our database is only used by one application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

真心难拥有 2024-08-11 23:55:55

我不会说他们本身就灰心丧气。对于 CakePHP 和 Rails,外键提供的数据完整性由框架处理。也就是说,只有当你以“正确”的方式做每件事时,这才是正确的。如果您正在编写自己的 SQL、以非标准方式操作或通过任何其他方式访问/操作数据,那么在我看来,外键绝对是一个好主意。

我从未使用过 CakePHP 的迁移工具,但在我有限的 Rails 工作中,我总是使用 SQL 在迁移中应用密钥。这样您就可以获得两者的所有固有好处。你有你的迁移,你有你的领域限制,以防你为了达到某些特定的结果而绕过框架。

I wouldn't say that they're discouraged, per se. With both CakePHP and Rails, the data integrity that foreign keys offer is handled by the framework. That said, it's only true if you do everything the "right" way. If you're writing your own SQL, operating in a non-standard manner or accessing/manipulating the data through any other means, then foreign keys are definitely a good idea, in my opinion.

I've never used migration tools for CakePHP, but in my limited Rails work, I've always applied the keys in the migration using SQL. That way you get all of the inherent benefits of both. You have your migration and you get your domain constraints in case you ever skirt the framework to achieve some particular result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文