Re: Efficiently finding elements with 0 has_many elements?

[prev] [thread] [next] [Date index for 2005/04/22]

From: Michael Peters
Subject: Re: Efficiently finding elements with 0 has_many elements?
Date: 14:38 on 22 Apr 2005
dglasser@xxxxx.xxx wrote:
> Say I have a class Item and a class Data; each Item has_many Data, and
> each Data has_a Item.
> 
> Is there an efficient way to find the rows of Item which have no Data?
> I can do a retrieve_all on Item and iterate through them looking for
> which ones have an empty $item->data, but it seems like I ought to be
> able to do this operation in the database.

One of the nicest things about C::D is that when you try to do something
that isn't necessarily built-in or efficient to do in Perl, you can
always have the database do it.

Something like this should work for you (depending on how you've named
your columns):

__PACKAGE__->add_constructor(
    retrieve_all_no_data => 'item.data IS NULL'
);


        -- 
        Michael Peters
Developer
Plus Three, LP

Re: Efficiently finding elements with 0 has_many elements?
Michael Peters 14:38 on 22 Apr 2005

Generated at 09:29 on 27 Apr 2005 by mariachi v0.52