Re: Search for specific field rather than primary key

[prev] [thread] [next] [Date index for 2004/08/12]

From: Dana Hudes
Subject: Re: Search for specific field rather than primary key
Date: 19:31 on 12 Aug 2004
On Thu, 12 Aug 2004, Kevin Old wrote:
> 
> I'm just curious if the code below that looks in the
> Pilot::StoreBrandXref table for a particular store, and has an
> iterator created in order to get to the brandid field.
> 
> my $bds = Pilot::StoreBrandXref->search({store => $store});
> 
> while (my $k = $bds->next) {
>         push @{$form_data{brand}}, $k->brandid;
> }
> print join(",", @{$form_data{brand}}), "<br>";
> 
> If I were to say:
> 
> my @bds = Pilot::StoreBrandXref->search({store => $store});
> 
> the bds array would be an array of the primary keys with store
> matching my search.

no you get an array of  Pilot::StoreBrandXref objects.
if you were to specify your search correctly; what you have isn't quite 
right. Try it w/o the embedded {}:
 my @bds = Pilot::StoreBrandXref->search(store => $store);

unless of course store is the single column primary key of 
Pilot::StoreBrandXref in which case you could just use 

	@bds = Pilot::StoreBrandXref->retrieve($store);


> 
> Is there not a way for me to specify the field I'd like returned
> rather than having to create an iterator to get to the field I'd like
> to?
> 

you don't have to create an iterator. if you have a million rows it might 
be advisable. I know the DBD::Pg driver developers are working to support 
cursors and thereby allow you to get e.g. a dozen at a time.

(message missing)

Re: Search for specific field rather than primary key
Dana Hudes 19:31 on 12 Aug 2004

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