[CDBI] Why does CDBI not populate the object on insert
Bill Moseley <[email protected]> Thu, 5 Mar 2009 10:14:41 -0800
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
This list is pretty quiet these days.
I'm looking at some old code and feeling a bit rusty with CDBI and
wondering about something. My guess is I've just forgot the reasoning
here:
If I do:
my $artist = Artist->insert({ name => 'Artist Name' });
then $artist->name doesn't exist yet in the object. That means, of
course, that $artist->name must do another fetch of the database.
I suppose there could be times when "name" comes back out of the
database different than it went in, but most of the time not.
Just seems a bit inefficient.
Actually, where I noticed this is with deeply nested tables. For
example, I have a $world object:
$country = Country->insert({ world => $world } );
$state = State->insert( { country => $country } );
$city = City->insert( { state => $state } );
$hood = Hood->insert( { city => $state } );
Then later, this ends up doing a select for each one, even though
we have the objects for each one.
my $country = $hood->city->state->country;
In other words, I wonder what would break if after _insert() was
called the object got set. That is, effectively:
$country = Country->insert({ world => $world } );
$country->{world} = $world;
--
Bill Moseley
[email protected]
Sent from my iMutt