Alternatives to Active Record

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Alternatives to Active Record

Post by Luke »

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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

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)
(#10850)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I like Data Mappers, there the easiest to work with (although the hardest to code). Definitely check out Fowler's book.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

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)
what is O/RM?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

(#10850)
wei
Forum Contributor
Posts: 140
Joined: Wed Jul 12, 2006 12:18 am

Post by wei »

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/
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

I prefer Table Data Gateway because I like a finder style interface.
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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

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.
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.
(#10850)
Post Reply