Re: Problem with has_many and searching

[prev] [thread] [next] [Date index for 2004/10/05]

From: Perrin Harkins
Subject: Re: Problem with has_many and searching
Date: 17:47 on 05 Oct 2004
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


Re: Problem with has_many and searching
John Day 16:20 on 05 Oct 2004

Re: Problem with has_many and searching
Perrin Harkins 16:25 on 05 Oct 2004

Re: Problem with has_many and searching
John Day 17:38 on 05 Oct 2004

Re: Problem with has_many and searching
Perrin Harkins 17:47 on 05 Oct 2004

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