An ORM for Joomla

244 views
Skip to first unread message

dukeofgaming

unread,
Jun 11, 2009, 7:41:27 AM6/11/09
to Joomla! CMS Development
So, I'm a little confused now and I don't reall want to add additional
noise to the development of the JQuery class or disregard the valuable
work already done, but I feel compelled to point out the following.

The confusion is regarding the intentions of an ORM for Joomla. Back
some time I googled "joomla +orm" and found that this was something
being worked on, and its name was JODA (http://developer.joomla.org/
gsoc2008/multi-db-support.html). But recently thanks to twitter I got
to know through Rob Schley that this project is not active anymore,
some further research and I found this:
http://forum.joomla.org/viewtopic.php?f=326&t=195747&sid=daa718d9c34e75dde246cf0cb98d6081&start=150

There is also a couple of things in stake here, when considering an
ORM implementation for Joomla this is: database abstraction and query
building. A custom ORM for Joomla might be the best option but there
is just so much to be done...

I've been working with the open source Doctrine ORM along with Joomla
for some time, and it feels quite natural. The Doctrine framework has
some really beautiful engineering behind, it includes database
abstraction and object oriented SQL (called DQL). Check them out at
ohloh http://www.ohloh.net/p/doctrine.

So, if we ever have an ORM for Joomla I think this is a great option
that would save the dev team a lot of work. Best of all, it is really
easy to integrate, just take a look at this pastie of my component
entry point: http://pastie.org/499691. The previous loads the models
in the environment and I can just do stuff like this for a save()
function:

$currency = new Currency();
if($id = JRequest::getVar('id')){
if($record = Doctrine::getTable('currencies')->find($id)){
$currency = &$record;
}else{
JError::raiseWarning(0,JText::_('RECORD_NOT_FOUND'));
$this->cpanel();
return;
}
}
$currency->name = JRequest::getVar('name');
$currency->symbol = JRequest::getVar('symbol');
$currency->status = JRequest::getVar('status');

try{
$currency->save();
JFactory::getApplication('site')->enqueueMessage(JText::_('SAVED'));
}catch(Exception $e){
JError::raiseWarning(0,JText::_('NOT_SAVED').': '.$e->getMessage());
}

You can take a look on the whole controller over here: http://pastie.org/508324.
Notice no models are being used.

I have some other projects in the stack and I sincerely intend to keep
using Doctrine instead of using JTable or any other classes... because
it is just better to use an ORM for most cases.

Integrating Doctrine as an external library would imply but not
limited to the following:
* Dealing with file and directory structure conventions for the
generated models, YAML definitions, etc...
* Refactoring and Integrating with JDatabase, JRecordSet, JModel,
JController, JQuery... etc.
* Tuning Doctrine's configuration accordingly for Joomla. An example
of this: http://pastie.org/508338
* Taking advantage of advanced functionality in the Doctrine such as
record hydration, paging, relations, etc.

The framework is exceptionally rich, beautifully designed, exception
driven and considers DBMS specific cases, very well documented and
nice developer support.

You can find the API here: http://www.doctrine-project.org/documentation/api/1_1
Manual and other documentation here: http://www.doctrine-project.org/documentation

There is of course a risk of relying heavily on a framework for such
an important task as this, however I find it to be the best supported
ORM framework for PHP and there is a version 2.0 coming with lots of
really delicious featurues thanks to the new technical commodities
that PHP 5.3.0 is bringing.

Could this be possible for, say, Joomla 1.7?, if not, are there any
SERIOUS plans for an ORM in the Joomla Framework?. Either way I think
there is so much to learn from Doctrine's design,
put special attention to this: http://www.doctrine-project.org/documentation/manual/1_1/en/technology

Thanks for your time

Amy Stephen

unread,
Jun 11, 2009, 10:20:31 AM6/11/09
to joomla-...@googlegroups.com
<offtopic>
Someone give this guy a 1.6 task! He is obviously knowledgeable about J! development and has interest! I say - load him up! hehe! (Seriously!)
</offtopic>

Schalk Versteeg

unread,
Jun 12, 2009, 6:28:08 AM6/12/09
to joomla-...@googlegroups.com
Hi Duke,

please have a look at this post


I see there where an ownerless joda branch in the Joomla SVN.

You could ask Hannes Papenberg to resurrect it or extract the code, that's if it was deleted.

Schalk Versteeg

dukeofgaming

unread,
Jul 9, 2009, 11:00:58 AM7/9/09
to joomla-...@googlegroups.com
Hi, sorry for the delay.

So I looked at the code from joda and found no real ORM value: there are a lot of SQL utility functions, some that seem to have made it to the JQuery class... some PDO extensions, some kind of sad implementation [sorry] of the relational part. It just keeps relying heavily on the notion of having to input SQL almost everywhere.

A long time ago I started to play around with the idea of making an ORM and I got some of it working [except the relational part, heh], then I started to mess with Doctrine and dropped this.

Here are the pasties:

Record class: http://pastie.org/540034
RecordField class: http://pastie.org/540038
RecordSet class: http://pastie.org/540043  //just has some notes

Here's an extract from the first example cited:

     * The definition of the Record is done by inheriting the abstract class and
     * implementing the abstract ¬archetype function.
     *
     * i.e.
     *
     *    class Foo extends Record{
     *        protected function ¬archetype(){
     *            $this->setTable('foos')
     *                ->setPrimaryKey('id','int')
     *                ->setField('bar','string');
     *        }
     *    }
     *
     *    $foo        = new Foo();                        //Empty object ready for assigning data
     *    $foo->bar    = "hello world";                    //RecordFields are accessed directly as if they were member variables
     *    if($foo->save()){                                //If the tuple is inserted
     *        $foo_reloaded        = new Foo($foo->id);    //the actual value(s) from the primary key(s) are updated into the object, and we use it (or them) to retrieve the data into the object
     *        $foo_reloaded->bar    = "Hello world!"        //We put more emotion into it!
     *        $foo_reloaded->save();                        //The save() method tries to update with the loaded primary keys
     *    }

Some highlights on the design of this are:
  • One defines the mapped tuple in the archetype method
  • One loads a record by passing the primary key(s) to the Record constructor
  • save() works as insert when primary key is not defined, and tries to work as update when otherwise
  • The RecordField object handles casting of the value stored
  • Relations are stored in the RecordField objects so one could navigate through the related records
What I left pending or partially implemented/thought-of/drafted:
  • XML definition exporting/importing
  • Flyweight pattern for the RecordSet
  • Native PHP iterator implementation for the RecordSet class
  • Array access for the Record class
  • The whole relational access implementation
  • N optimizations among where usage of the Enterprise application design patters should have been used/considered
  • Object Query Language sugar
So well... maybe some of this can be rescued, but then again, adopting Doctrine would be much nicer. If for some reason Doctrine ever ceased to exist (highly unlikely given the devbase/documentation/technology behind it), records are handled very similar to other ORMs and code could be saved just by following the same conventions (function names, attribute access & schema definition).

So, what do you guys think?

Mitch Pirtle

unread,
Jul 9, 2009, 11:11:13 AM7/9/09
to joomla-...@googlegroups.com
Lazy loading models, migrations, I'm like a pig in mud! Andrew,
remember when the only alternative to JDatabase was ADODB? (giggle)

This looks quite impressive, can't believe I've waited this long to
take a serious look at it. Already integrated with symfony and zend
(others too, but wiki is down). Looks like a promising candidate to
me. Checking it out on my own, too.

-- Mitch

dukeofgaming

unread,
Jul 27, 2009, 9:14:15 AM7/27/09
to Joomla! CMS Development
Hi again, just wanted to drop by and let you know that Doctrine 2.0
has started peeking to the surface (http://www.doctrine-project.org/
documentation/manual/2_0/en/introduction) and the documentation is
being developed right now. Doctrine 2.0 is PHP 5.3.0 and up btw.

So what do you guys think is more likely (and why)?, to integrate a
fully functional ORM framework and database abstraction layer, or to
start messing with Joomla's very own?.

Regards,

David

On Jul 9, 10:11 am, Mitch Pirtle <mitch.pir...@gmail.com> wrote:
> Lazy loading models, migrations, I'm like a pig in mud! Andrew,
> remember when the only alternative to JDatabase was ADODB? (giggle)
>
> This looks quite impressive, can't believe I've waited this long to
> take a serious look at it. Already integrated with symfony and zend
> (others too, but wiki is down). Looks like a promising candidate to
> me. Checking it out on my own, too.
>
> -- Mitch
>
> On Thu, Jul 9, 2009 at 11:00 AM, dukeofgaming<dukeofgam...@gmail.com> wrote:
> > Hi, sorry for the delay.
>
> > So I looked at the code from joda and found no realORMvalue: there are a
> > On Fri, Jun 12, 2009 at 5:28 AM, Schalk Versteeg <schalk.verst...@gmail.com>
> > wrote:
>
> >> Hi Duke,
> >> please have a look at this post
>
> >>http://groups.google.com/group/joomla-dev-cms/browse_thread/thread/5f...
> >> I see there where an ownerless joda branch in the Joomla SVN.
> >> You could ask Hannes Papenberg to resurrect it or extract the code, that's
> >> if it was deleted.
> >> Schalk Versteeg
>
> >> On Thu, Jun 11, 2009 at 4:20 PM, Amy Stephen <amystep...@gmail.com> wrote:
>
> >>> <offtopic>
> >>> Someone give this guy a 1.6 task! He is obviously knowledgeable about J!
> >>> development and has interest! I say - load him up! hehe! (Seriously!)
> >>> </offtopic>
>
> >>> On Thu, Jun 11, 2009 at 6:41 AM, dukeofgaming <dukeofgam...@gmail.com>
> >>> wrote:
>
> >>>> So, I'm a little confused now and I don't reall want to add additional
> >>>> noise to the development of the JQuery class or disregard the valuable
> >>>> work already done, but I feel compelled to point out the following.
>
> >>>> The confusion is regarding the intentions of anORMfor Joomla. Back
> >>>> some time I googled "joomla +orm" and found that this was something
> >>>> being worked on, and its name was JODA (http://developer.joomla.org/
> >>>> gsoc2008/multi-db-support.html). But recently thanks to twitter I got
> >>>> to know through Rob Schley that this project is not active anymore,
> >>>> some further research and I found this:
>
> >>>>http://forum.joomla.org/viewtopic.php?f=326&t=195747&sid=daa718d9c34e...
>
> >>>> There is also a couple of things in stake here, when considering an
> >>>>ORMimplementation for Joomla this is: database abstraction and query
> >>>> building. A customORMfor Joomla might be the best option but there
> >>>> is just so much to be done...
>
> >>>> I've been working with the open source DoctrineORMalong with Joomla
> >>>> for some time, and it feels quite natural. The Doctrine framework has
> >>>> some really beautiful engineering behind, it includes database
> >>>> abstraction and object oriented SQL (called DQL). Check them out at
> >>>> ohlohhttp://www.ohloh.net/p/doctrine.
>
> >>>> So, if we ever have anORMfor Joomla I think this is a great option
> >>>> it is just better to use anORMfor most cases.
>
> >>>> Integrating Doctrine as an external library would imply but not
> >>>> limited to the following:
> >>>> * Dealing with file and directory structure conventions for the
> >>>> generated models, YAML definitions, etc...
> >>>> * Refactoring and Integrating with JDatabase, JRecordSet, JModel,
> >>>> JController, JQuery... etc.
> >>>> * Tuning Doctrine's configuration accordingly for Joomla. An example
> >>>> of this:http://pastie.org/508338
> >>>> * Taking advantage of advanced functionality in the Doctrine such as
> >>>> record hydration, paging, relations, etc.
>
> >>>> The framework is exceptionally rich, beautifully designed, exception
> >>>> driven and considers DBMS specific cases, very well documented and
> >>>> nice developer support.
>
> >>>> You can find the API here:
> >>>>http://www.doctrine-project.org/documentation/api/1_1
> >>>> Manual and other documentation here:
> >>>>http://www.doctrine-project.org/documentation
>
> >>>> There is of course a risk of relying heavily on a framework for such
> >>>> an important task as this, however I find it to be the best supported
> >>>>ORMframework for PHP and there is a version 2.0 coming with lots of
> >>>> really delicious featurues thanks to the new technical commodities
> >>>> that PHP 5.3.0 is bringing.
>
> >>>> Could this be possible for, say, Joomla 1.7?, if not, are there any
> >>>> SERIOUS plans for anORMin the Joomla Framework?. Either way I think
Reply all
Reply to author
Forward
0 new messages