[Dbix-class] DBIx::Class::Direct: what's wrong with that ?

Dami Laurent (PJ) laurent.dami at justice.ge.ch
Mon Jun 7 06:56:04 GMT 2010


 

>-----Message d'origine-----
>De : Marc Chantreux [mailto:khatar at phear.org] 
>Envoyé : dimanche, 6. juin 2010 01:14
>À : dbix-class at lists.scsys.co.uk
>Objet : [Dbix-class] DBIx::Class::Direct: what's wrong with that ?
>
>hello all, 
>
>I'm pretty new in the ORM world and i'm trying to figure out how to
>write very simple webapps as quick as possible. DBIx::Class is awesome
>and i would like to use it to add persistence to my buziness objects. 
>
>For a given Users class, i would like to write Users->search({}), not
>$schema->resultset('Users')->search().
>

Salut Marc,

Various ORMs differ in modelling schema and tables : some use classes, some use object instances. Old Class::DBI was class-based. DBIx::Class was initially class-based, and then switched to instance-based after a couple of months of existence. 

The advantage of instance-based is that it allows you to connect simultaneously to several databases that have the same structure. This is precious for example for architectures with mirroring, load-balancing, or that kind of situations, which is the reason why modern ORMs tend to adopt the instance-based approach. But, as you noticed, the cost is that you have to pass such instances around, or to constantly call accessor methods like $schema->resultset(...).

An example of the other approach is DBIx::DataModel, that sticked to class-based, so it has the convenience of direct access to tables, and also the fact that row objects contain no other information than mere data coming from the database ... but the price to pay is more difficulty for managing multiple databases. The solution was to introduce a $schema->localizeState() method, that more or less works like the "local" feature for Perl variables ... it works well, but I admit it is a bit more awkward.

Since DBIx::Class explicitly chose the instance-based approach, you have to stick to it, or change ORM, but don't add class-based access on top of an instance-based framework, or you will end up in a conceptual mess.

Laurent Dami



More information about the DBIx-Class mailing list