ActiveRecord 模式是否仅适用于具有较简单数据访问要求的应用程序?
我是 ActiveRecord 模式的一个相对较新的用户。我想知道这种模式对于大型关系数据库是否实用。假设我们有大约 15 个相关表,使用 AR 模式进行 CRUD 有意义吗? 例如:
tblCustomer
tblCustomerNames
tblCustomerAddresses
tblCustomerDocuments
tblCustomerPhoneNumbers
等等。 请注意,一位客户可能有多个姓名(如未婚、法定姓名等)、多个地址。出于某种原因,我有一种感觉,如果我们使用存储过程来代替,会更好更快。可能是我回到了习惯,但如果我错了,请纠正我。
I am a relatively new user of the ActiveRecord pattern. I was wondering if this pattern is practical for a large relational database. Say we have about 15 related tables, does it make sense to do CRUD using the AR pattern ?
For example:
tblCustomer
tblCustomerNames
tblCustomerAddresses
tblCustomerDocuments
tblCustomerPhoneNumbers
and so on..
notice that a customer may have more than one name (like maiden,legal etc), more than one addreses. For some reason I have a feeling that it would be better and faster if we use a stored procedure instead. It may be me going back to what I am used to, but please correct me if I am wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的。在加载相关数据时,Active Record 模式可能会变得非常繁琐。有一些技术可以避免这种情况,但一般来说,我会创建一组视图来公开您需要的数据。在我看来,最好仅将特定屏幕上所需的数据公开为只读视图,并使用存储过程执行修改。
出于安全考虑,CRUD 应该通过存储过程进行。使用存储过程为您提供了额外的优势 - 您可以更改操作的内部逻辑,而无需更改客户端代码。
You are right. Active Record pattern can become extremely chatty when it comes to loading related data. There are some techniques of avoiding this, but in general, I would create a set of views that expose the data you need. In my opinion it is better to expose only data you need on particular screen as read only view and perform modifications using stored procedures.
The CRUD should be made through stored procedures also because of the security concerns. Using stored procedure gives you additional advantage - you can change internal logic of the operation without having to change the client code.