Part of the EllisLab Network
   
1 of 3
1
How badly do we want ORM?
Posted: 11 July 2007 02:32 PM   [ Ignore ]  
Summer Student
Total Posts:  2
Joined  09-14-2006

Just how badly is ORM wanted by the CI community?  I have been working on a very simple helper that would “bolt on” ORM.  It seems very promising, although it’s a long way to alpha.

However, it does appear that the overhead of creating objects out of rows in an array is significant.  I’m using lazy instantiation to avoid objectifying any particular result until directly called, but this still adds quite a bit of overhead.  My initial tests show a slightly exponential increase in load times as the number of records increases.  At ten records, the difference between standard array iteration and iteration with instantiation is not noticeable- in fact, sometimes with ORM proved to be faster (almost certainly due to other processes going on in the environment).  At 100 records, the difference is in hundredths of a second.  At 10,000 results, the difference is just under a 100% increase in load time.

The alternative is to have a function wrapper that accepts a row as input and manually generates an object.  The disadvantage is that this would not be able to introspect if the result already exists, and would not be able to have a universal save() method without an extra parameter being passed to the wrapper function.  However, this would allow native speeds and only instantiate where specifically needed.

After having several people look over the code (which is very bare bones at this point- it’s simply a wrapper class) and trying a few techniques and methods to iterate (tail recursion, for and foreach iteration, etc.), the trend in load times seems to equal out across the board.  I think the problem is simply the overhead of PHP objects (as they were sort of “bolted on” as well).

So, do you guys think it’s worth continuing and creating a finished product that can be added into a project?  For your uses of CI, is that an acceptable overhead?

Profile
 
 
Posted: 11 July 2007 02:51 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  770
Joined  02-06-2007

There are so many mature ORM options available:

1. DB_DataObject
2. EZPDO (php 5 only)
3. Propel (php 5 only)

Personally, I don’t see the point in creating another unless it offers something different. It would be a monumental task to create a complete ORM from scratch. A tutorial for using an existing ORM within CI would be valuable though.

 Signature 

“I am the terror that flaps in the night”

Profile
 
 
Posted: 11 July 2007 04:47 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  2
Joined  09-14-2006

Most likely, no outside ORM will use CI’s db library or active record class.  And Propel (if I remember it correctly) in particular is an inelegant solution, in that it uses XML to describe models (which is elegant when talked about but inelegant to program with).  I was not actually talking about modeling data- CI already has models.  I was talking about extending data objects to make them more expressive to work with.  Granted, this does not fully embody the paradigm of ORM, but then again, CI doesn’t embody the full paradigm of MVC.

PHP is not an extremely expressive language to use for modeling, anyway.  It’s kind of a web templating tool for Perl that got away from its authors smile

Anyway, my tactic is to prototype a basic result struct for each row returned that would have methods for saving, deleting, and finding related records across relationships, introspected from the query itself.

Profile
 
 
Posted: 12 July 2007 01:42 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  206
Joined  04-27-2006

I just want say, there is another orm library named
Doctrine

Profile
 
 
Posted: 15 July 2007 11:12 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  206
Joined  04-27-2006

has someone tried Doctrine and can help me?
I want try it, but cannot download it - the download link is broken and the other download possibility is via svn, that I donĀ“t know to use…

maybe someone can mail me the zipped package? (please ask first)

Profile
 
 
Posted: 17 July 2007 06:04 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  1
Joined  07-17-2007

LuTze,

I would love native ORM in CI.  I’ve been pining for it badly over the last couple of days and I’ve been keeping a project halted while I decide between CI and the CakePHP framework (which has ORM built in).

Cake is too bloated and restrictive for me though and I don’t think even ORM is worth the switch.

For me, CI would be complete with relational models!

- Nick

Profile
 
 
Posted: 15 August 2007 08:32 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  206
Joined  04-27-2006

finally I could download doctrine, but its the pure horror, so complicated to setup, at least it seems to me - and nobody there at there forum to help

Profile
 
 
Posted: 15 August 2007 10:51 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  39
Joined  09-17-2004

I honestly don’t understand why most of the ORM solutions are so complicated.

I’m currently building a rather large application, and if I decided to use CI, I’ll then rebuild my simple ORM library. wink

 Signature 

Fred Wu
Founder of Wuit.com | Web Developer at Envato
My blog: fredwu.me | Follow me @fredwu

Profile
 
 
Posted: 15 August 2007 05:18 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
RankRankRank
Total Posts:  530
Joined  07-10-2006
gunter - 15 August 2007 12:32 PM

finally I could download doctrine, but its the pure horror, so complicated to setup, at least it seems to me - and nobody there at there forum to help

Doctrine got a Google Summer of Code 2007 project and some major refactoring is underway to make the API more modular and robust. Other changes are also underway to get ready for PHP6. The documentation needs some serious work, but that will probably have to come later after the number of developer commits drops to a reasonable level.

Profile
 
 
Posted: 15 August 2007 05:26 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
RankRank
Total Posts:  234
Joined  03-12-2007

ORM would be nice - would def. speed development.

Profile
 
 
Posted: 15 August 2007 06:08 PM   [ Ignore ]   [ # 10 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4777
Joined  03-23-2006

ORM is one of the things that we’ve publicly stated is on the radar.  At this point though, Cake’s ORM is more mature then ours.

James Nicol, who used to be really active, but lately has been bogged down with other stuff, has written up some useful stuff on his site also.  Just visit the front page and you’ll see a bunch of CodeIgniter articles.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
MSG
 
 
   
1 of 3
1