PHP/CI 中的简单相关查询是否需要 ORM?
我按照 Codeigniter 的文档视频非常简单地启动了我的应用程序。
我有下表:
Account
account_id
name
details
Contact
contact_id
account_id
name
address
Order
order_id
account_id
contact_id
date
description
Item
item_id
order_id
description
price
关系如下: 1 个账户处理多个订单 1 个帐户可容纳多个联系人 1 联系多个订单 1 订购许多商品
现在,当我尝试从仅传递订单表查询的视图中获取帐户名称时,查询可能会变得有点麻烦。
话虽如此,该应用程序非常简单,并且没有太多此类查询。
我只是想知道您对 ORM 的看法 - 您认为对于像这样的简单应用程序来说有必要吗?
I started my app very simply following the documentation videos for Codeigniter.
I have the following tables:
Account
account_id
name
details
Contact
contact_id
account_id
name
address
Order
order_id
account_id
contact_id
date
description
Item
item_id
order_id
description
price
Relationships are as follows:
1 Account to many orders
1 Account to many contacts
1 Contact to many orders
1 Order to many items
Now when I'm trying to get the account name from a view that's only passed a query from an order table, the queries can get a bit cumbersome.
In saying that, the app is quite simple and there's not too many of these queries.
I just want to know what your opinions are on ORMs - do you think one is necessary for a simple app like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定您的框架对您编写 SQL 的能力有何限制,但是不,您不需要 ORM。
SQL 是一种非常简单的语言,可以用来编写强大的查询。就像你所说的应用程序,更是如此。
使用框架、MVC、ORM、ABC、FBI 等……当您的目的是节省时间和简化时,您最终可能会花费更多的时间来满足框架依赖项,而不是为您节省时间,最终会陷入复杂的混乱。
不要忘记一组 UI 脚本和一些静态类在 PHP 中的功能是多么强大。
I'm not sure what constraints your framework places on your ability to write SQL, but no, you don't need an ORM.
SQL is a very simple language to write powerful queries in. For a simple application like you are talking about, all the more so.
With frameworks, MVC, ORM, ABC, FBI, etc... you can end up spending more time satisfying the framework dependencies than it saves you, ending up with a complicated mess, when the intent was to save time and simplify.
Don't forget how competent a set of UI scripts and a few static classes can be in PHP.
我会坚持使用 CodeIgniter 内置的 ActiveRecord。对于如此简单的数据来说,数据库之间的任何更多抽象都将是严重的过度杀伤力。
I would just stick with CodeIgniter's built in ActiveRecord. Any more abstraction between you are the database would be serious overkill for such simple data.
Codeigniter 的 Active Record 是一个很好的折衷方案:您不需要将所有数据库模式映射到类,但您可以获得一个方便的界面来为您处理一些事情。我认为它非常适合你的情况。
Codeigniter's Active Record is a good compromise: you don't need to map all your database schema to classes, but you get a convenient interface that takes care of some things for you. I think it's well suited for your situation.