[Dbix-class] Use of ->resultset mandatory?

Christopher H. Laco claco at chrislaco.com
Mon Oct 30 21:12:46 GMT 2006


Steven Mackenzie wrote:
> Mike Friedman wrote:
> =

>> Greetings,
>>
>> I'm used to Class::DBI and very new to DBIx::Class.
>>
>>> From the docs, it seems like to execute any search, I have to
>>
>> 1. Instantiate a schema object and connect it
>> 2. Call $schema->resultset('MyTableClass')->search( ... );
>>
>> In Class::DBI, since the table classes generally inherit from the main DB
>> class, I can just call MyTableClass->search( ... ) which seems a lot
>> simpler. (And less to type.)
>>
>> Is there a similar way to achieve this simpler syntax with
>> DBIx::Class, or
>> do I have to use $schema->resultset every time?
>> Is there a recommended way to encapsulate connection parameters, so I
>> don't
>> have to call $schema->connect all over the place?
>>
>> (Note: I'm not trying to be obnoxious, I just don't really quite
>> understand
>> how DBIC is organized just yet.)
>>
>> Thanks,
>> Mike
> =

> Sorry, I don't know, but I'd love to hear the answers too - can I add an
> extra (sort of related) question to the list?
> =

> Why is there no accessor in the schema class for each table? Wouldn't it
> be obvious to type
>  $schema->MyTableClass->search( .. )
> =

> Not quite as brief as the CDBI style, but resultset('') starts to hurt
> my fingers (especially the punctuation parts of it ...)
> =

> Steven

Don't always assume that table eq 'tableclass', or even schema class.
The three need not be related by name in any way.

  package My::Schema::Foo;
  __PACKAGE__->table('stuff');
  __PACKAGE__->source_name('MyBar');

  $schema->resultset('MyBar')->search;


  package My::Schema::Foo2;
  __PACKAGE__->table('stuff');
  __PACKAGE__->add_column('evenmore');
  __PACKAGE__->source_name('MyBest');

  $schema->resultset('MyBest')->search;


You can use two resultsource classes against the same table(), kind of
like inherited tables.


-=3DChris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://jules.scsys.co.uk/pipermail/dbix-class/attachments/20061030/d0=
0520b9/signature.pgp


More information about the DBIx-Class mailing list