Re: loading many objects from one query

[prev] [thread] [next] [Date index for 2004/09/14]

From: Andrew Pimlott
Subject: Re: loading many objects from one query
Date: 23:05 on 14 Sep 2004
On Tue, Sep 14, 2004 at 10:09:45AM +0100, Tim Bunce wrote:
> On Mon, Sep 13, 2004 at 10:22:37PM -0400, Perrin Harkins wrote:
> > The ability to construct objects from data that you fetched on your own 
> > is already there, in the form of the method "construct".
> 
> And here's an example you posted yourself a while ago:

Thanks for the ideas and example.

>     my $row = $sth->fetchrow_arrayref();
>     my $foo = Foo->construct({
>                               id    => $row->[0],
>                               other => $row->[1],
>                              });

It seems that in most cases, you should be able to do

    my $row = $sth->fetchrow_arrayref();
    my $foo = Foo->construct($row);
    my $foo = Bar->construct($row);

(Probably there are some cases, eg with an outer join, when it's not so
simple.)  For those cases, it "would be nice" if you could simply tell
Class::DBI, build a Foo, a Bar, and a Baz for every row returned by this
query, and give me back the (unique) Foos.

>     $foo->{'_bar_object'} = $bar;

But how to automate this... ?  IOW, I'd like to be able to tell
Class::DBI, in a structured way, that every Foo "has_a" the Bar from the
same row, or the Bazs comprise the "has_many" of the Foos.  Not that I
absolutely need this, but I think it would be powerful and interesting.

Andrew

(message missing)

loading many objects from one query
Andrew Pimlott 01:05 on 14 Sep 2004

Re: loading many objects from one query
Perrin Harkins 02:22 on 14 Sep 2004

Re: loading many objects from one query
Tim Bunce 09:09 on 14 Sep 2004

Re: loading many objects from one query
Perrin Harkins 14:21 on 14 Sep 2004

Re: loading many objects from one query
Tim Bunce 16:07 on 14 Sep 2004

Re: loading many objects from one query
Perrin Harkins 16:12 on 14 Sep 2004

Re: loading many objects from one query
Andrew Pimlott 23:05 on 14 Sep 2004

Re: loading many objects from one query
Perrin Harkins 23:22 on 14 Sep 2004

Re: loading many objects from one query
Todd Lorenz 16:13 on 14 Sep 2004

Re: loading many objects from one query
Tim Bunce 13:52 on 15 Sep 2004

Re: loading many objects from one query
Perrin Harkins 15:22 on 15 Sep 2004

Re: loading many objects from one query
merlyn (Randal L. Schwartz) 17:10 on 16 Sep 2004

Re: loading many objects from one query
Andrew Pimlott 19:17 on 16 Sep 2004

Re: loading many objects from one query
Tim Bunce 17:36 on 14 Sep 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52