ActiveRecord

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
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

ActiveRecord

Post by Maugrim_The_Reaper »

In the past few days I've been trying to figure out the latest hype over this ActiveRecord ORM approach (I blame it on Ruby on Rails!). It seems everyone and their dog is adding it to PHP Frameworks - even Zend apparently (though their use case seems to contravene the workings of PHP). What's confusing as hell however is the focus on metaprogramming - why do so many of these have "SHOW COLUMNS" sql calls (a mysql example) that must have occured to someone as a bit iffy performance wise? Is it necessary to automagically generate ActiveRecord subclasses at runtime? And why is so much functionality bundled into the parent class - and copied to evey inheriting object, rather than some abstracting all this repitition out to a referenced third object (saving on the memory it eats - which is important for many of us on shared hosts).

The more I look, the more I dislike, or itch to change. I even got confused after figuring out too late its not even the ActiveRecord design pattern Fowler describes!

Wondering if anyone here is using ActiveRecord (not the Fowler pattern - the Ruby On Rails misnamed one), and whether anyone has been convinced of its advantages (if any) over more traditional ORM methods...
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Is it metadata mapping?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Basically... The versions I keep finding are running a SHOW COLUMNS query (if MySQL), collecting table and field information, saving these to object properties, and using as a basis for ActiveRecord methods (the save(), get() etc when generating SQL). I would have thought straight code generation of all these classes make a lot more sense. But then domain objects are extending the ActiveRecord - so it needs to customise itself for every instantiation.

That can add up to a lot of SQL queries to collect metainformation depending on the number of domain objects for data representation... Doesn't seem worth the performance hit.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If i'm not mistaken pear DataObjects only generates the actuall classes when you ask for it (run show columns etc...) After that it always uses the cache... I think most implementations are moving towards this approach..
Post Reply