Re: Efficiently finding elements with 0 has_many elements?
[prev]
[thread]
[next]
[Date index for 2005/04/22]
David Glasser wrote:
> On 4/22/05, Michael Peters <mpeters@xxxxxxxxx.xxx> wrote:
>
>>dglasser@xxxxx.xxx wrote:
>>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'
>>);
>
>
> Hmm. So I bet it'll still be something along the lines of that, but
> the issue is that my Item doesn't have a data column -- it's a
> has_many, and the Data have item columns. Can something like this
> still work?
Sorry... don't know why I did though has_a even though you said
has_many. But, yes it's still just a matter of finding the right SQL
that would give you the rows for the Item that you want. Then you can
use something like set_sql() to execute it and give you the objects you
want. And if you need more power, you can get the db handle, create a
statement handle, execute it and then pass it to sth_to_objects().
Either way, the database is still doing the work.
--
Michael Peters
Developer
Plus Three, LP