Alternatives to Active Record
Moderator: General Moderators
Alternatives to Active Record
I have read a lot about how the active record works great for its purpose, but isn't very efficient. The fact that each record has to be worked with individual hinders performance. Are there better patterns all-around, or does it just depend on the circumstance?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I prefer Table Data Gateway because I like a finder style interface. But Active Record with some O/RM thrown in is all the rage since Ruby on Rails.
Fowler catalogs them as Data Source Architectural Patterns here (second row)
Fowler catalogs them as Data Source Architectural Patterns here (second row)
(#10850)
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
what is O/RM?arborint wrote:I prefer Table Data Gateway because I like a finder style interface. But Active Record with some O/RM thrown in is all the rage since Ruby on Rails.
Fowler catalogs them as Data Source Architectural Patterns here (second row)
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
If you prefer SQL and be able to utilize more features of your database engine then something like the Ibatis data mapper (avaiable in java and .net, and sort of for php) is ideal.
e.g.
http://ibatis.apache.org/
e.g.
http://ibatis.apache.org/
Wouldn't a Table Data Gateway often be a good solution for a CRUD-like application in which normalized db tables are used? Like the object User in Fowlers example, or an object Product in a shop. In fact, thinking about it, this pattern is something you'll end up with almost naturally. For example, when you have your db tables users, widgets, transactions and corresponding classes.I prefer Table Data Gateway because I like a finder style interface.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Exactly. I remember when I first learned Table Data Gateway. I had been building similar classes for thing like CRUD and User objects just as you say. Then I saw Table Data Gateway and realized how poor quality and inconsistent my code was. It is a Best Practice pattern for very common code.matthijs wrote:Wouldn't a Table Data Gateway often be a good solution for a CRUD-like application in which normalized db tables are used? Like the object User in Fowlers example, or an object Product in a shop. In fact, thinking about it, this pattern is something you'll end up with almost naturally. For example, when you have your db tables users, widgets, transactions and corresponding classes.
(#10850)