Using 'in' in add_constructor

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

From:
Subject: Using 'in' in add_constructor
Date: 10:33 on 27 Sep 2004
Dear list,

in one of my classes I add the following constructor:

__PACKAGE__->add_constructor( links_in =3D> 'link_id in ( ? )' );

If I understand the way add_constructor works correctly, this is
equivalent to
select __ESSENTIAL__ from __TABLE__ where link_id in ( ? )

Correct?

link_id is a single value primary key for this table.

In my source code I do

    my $it =3D Links->links_in( '1,2,3,4' );
    $self->log->debug( Dumper( $it ) );
    while ( my $link_id =3D $it->next ) {
	# .. do sth.
    }

and this yields only one hit for the first value passed in, in this case
for link_id 1.


The Dumper output shows
$VAR1 =3D bless( {
                 '_data' =3D> [
                              {
                                'link_id' =3D> '1'
                              }
                            ],
                 '_class' =3D> 'Links',
                 '_place' =3D> 0,
                 '_mapper' =3D> []
               }, 'Class::DBI::Iterator' );


Now, if I use the above statement on a command-line interface to my
MySQL-DB (replacing __ESSENTIAL__ and __TABLE__ with appropriate values,
of course), this yields the expected four hits with the corresponding
link_ids.

Can I get back multiple link_ids without having to do a search or
retrieve for every single value? I thought the way I tried to do it was
the way it could be done, but obviously I erred ... ?


Thanks,
Daniel.


Using 'in' in add_constructor
10:33 on 27 Sep 2004

Re: Using 'in' in add_constructor
merlyn (Randal L. Schwartz) 11:46 on 27 Sep 2004

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