开发者

Is ActiveRecord pattern suitable only for apps that have simpler DataAccess requirements?

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜