Re: Problem with has_many and searching
[prev]
[thread]
[next]
[Date index for 2004/10/05]
On Tue, 2004-10-05 at 19:38, John Day wrote:
> My problem is I need to figure out how to get an iterator that points to
> the 'contact' records, not the contactdetail records.
Oh, now I understand. You want to find the parent objects based on
something in the child objects. That's not what has_many does.
There are two ways to do this. The simple, but not terribly inefficient
way is to take the iterator you have (or just run a search on the
contactdetail class instead) and fetch the parent objects from it:
while ( my $detail = $iterator->next() ) {
my $contact = $detail->contact_id();
}
This does an extra query. If you're worried about the extra query,
you'll have to write a custom search method on your contact class using
SQL that joins the tables. See the Ima::DBI Queries section of the docs
for more on that.
- Perrin