[Dbix-class] DBIx::Class:Schema::Loader has_many relationshipnames

Matt S Trout dbix-class at trout.me.uk
Fri Feb 24 21:13:32 CET 2006


On Fri, Feb 24, 2006 at 06:49:06PM +0100, Adam Sjøgren wrote:
> On Fri, 24 Feb 2006 17:18:08 -0000, Peter wrote:
> > my $car = DB::Car->find( name => 'Ford Focus' );
> > (one car record)
> 
> (This reads funny in my head - find a car amongst one car?)

Yeah, that'd be

my $car = $schema->resultset('Car')->find('Ford Focus');

Don't use classmethods. Really, don't. It's a Class::DBI-ism we accidentally
inherited for a bit and it's (a) fugly (b) limits you to a single database
connection (c) clutters your namespaces up (d) is bad design (e) adds an
extra sub call while the code goes through ResultSetProxy to do it
properly :)
 
> > my $car = DB::Cars->find( name => 'Ford Focus' );
> > (is that one car or many? is $car a record or a recordset? should the
> > variable be $cars?)
> 
> Even if I call the table cars, I would have the object that wraps a
> single record be named MyApp::Car.
> 
> So my answer would be that the second 'my' should be 'my $cars=' and
> hold a recordset - each record in that should be of a class called
> MyApp::Car, representing one car.

That's what a DBIx::Class::ResultSet is for.

What I usually do is declare a custom ResultSet class called 'DB::Cars'

so

my $DB_Cars = $schema->resultset('Car');

my @DB_Car = $DB_Cars->all;
 
> (I (think I) understand that that kind of naming does not map really
> well to the way the ORM works, but above I'm just stating what makes
> sense "in my head", when I read it. My head will have to adapt).

I think you might be wrong - see above.

The separation of ResultSource (table), ResultSet (recordset) and Row classes
in 0.05 was specifically so you could end up with a sensible mapping of
such concepts to OO-land :)

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list