[CDBI] Preloading objects when using a view

Bill Moseley moseley at hank.org
Wed Mar 29 01:35:32 BST 2006


On Tue, Mar 28, 2006 at 07:27:19PM -0500, Perrin Harkins wrote:
> On Tue, 2006-03-28 at 16:10 -0800, Bill Moseley wrote:
> > Now, say, the view also returns the artist name.  What I'd like to do
> > is have CDBI populate the "name" column of the artist object it
> > created as a result of the search on the view class.  That way I'd
> > avoid a second trip to the database.
> 
> Do you fetch the view object with retrieve()?  You could probably
> override that and hard-code the filling in of the name.  Or you could
> override something internal in this class, like construct().

I'm looking into overriding _init, as Sweet does.

I suppose I could override search() and then loop through the results
and populate the columns in the related objects.

> I'd probably just switch to Rose::DB::Object rather than trying to build
> this into CDBI, but I can see why that would be a non-starter if you
> have a big codebase here.

Yes, that's the problem -- but it won't keep John and Matt from
pestering me about changing. ;)

-- 
Bill Moseley
moseley at hank.org





More information about the ClassDBI mailing list