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

Hartmaier Alexander Alexander.Hartmaier at t-systems.at
Tue Oct 31 14:01:23 GMT 2006


> -----Original Message-----
> From: Shane McEwan [mailto:linenoise at virtualdoughnutland.com]
> Sent: Tuesday, October 31, 2006 12:33 AM
> To: dbix-class at lists.rawmode.org
> Subject: Re: [Dbix-class] Use of ->resultset mandatory?
> 
> On Mon, 2006-10-30 at 21:43 +0000, Steven Mackenzie wrote:
> > In my quest to avoid typing resultset(''), is there a reason why I
> can't
> > have source_name create accessors in the $shema object, eg,
> >   $schema->MyBest->search;
> 
> I'm also new to DBIx::Class after using CDBI for a couple of years and I
> had the exact same question.
> 
> I saved myself some typing by doing:
> 
> my $MyBest = $schema->resultset('MyBest');
> $MyBest->search();
> 
> It seems to work but I've only done very basic stuff so far. Please let
> me know if what I'm doing is stupid and will break when I try to do
> something more complicated.
> 
> I still haven't got my head around exactly what a result set is and what
> I can do with it. I subscribed to the mailing list to hopefully see some
> examples of what other people are doing. So far this is the first
> question I've been able to understand. :-)
> 
> As I learn more I may be tempted to write a CDBI to DBIC transition
> guide.
> 
> Shane.


ResultSets are the most brilliant idea ever ;-)
A ResultSet as an object which creates sql queries for you and returns the data.
The advantage is that the sql isn neither generated nor executed when you create a rs but not until you fetch data with ->next, ->all or by using it list context (e.g. @cds = $rs_favorite_cds;).
This makes it possible to generate a resultset and extend it as often as you like to prefetch additional relationships, change the search criteria and so on.

For example you can use dbic in catalyst and filter on different things:

url: /requests/mine/open:
	in requests: create a resultset with all requests and store it in the stash
     in mine: extend it to filter only the requests of the logged in user
     in open: extend it again to filter on only open requests

I'm pretty sure this works wonderful together with ChainedActions, but it wasn't born when I coded my last cat app.

-Alex
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*




More information about the DBIx-Class mailing list