Re: Problem with has_many and searching
[prev]
[thread]
[next]
[Date index for 2004/10/05]
Some progress?
At 12:06 PM 10/5/2004, you wrote:
>Using Class::DBI 0.96, Class::DBI::mysql ..........
>I have a pair of simple tables declared like this in my Class::DBI module:
According to the Class::DBI docs, the class witht he has_a() must be
declared before the class with the has_many(). So I fixed that.
package InContact::cDBI::contactdetail;
use base 'InContact::cDBI';
__PACKAGE__->set_up_table('contactdetail');
__PACKAGE__->has_a('contact_id' => 'InContact::cDBI::contact');
package InContact::cDBI::contact;
use base 'InContact::cDBI';
__PACKAGE__->set_up_table('contact');
__PACKAGE__->has_many('contact_detail' => 'InContact::cDBI::contactdetail',
'contact_id');
>package InContact::cDBI::contact;
>use base 'InContact::cDBI';
>
>__PACKAGE__->set_up_table('contact');
>__PACKAGE__->has_many('contact_detail' =>
>'InContact::cDBI::contactdetail', 'contact_id');
>
>package InContact::cDBI::contactdetail;
>use base 'InContact::cDBI';
>
>__PACKAGE__->set_up_table('contactdetail');
>__PACKAGE__->has_a('contact_id' => 'InContact::cDBI::contact');
>
>What I want is an iterator pointing to all records in
>InContact::cDBI::contact which have a matching
>InContact::cDBI::contactdetail where the value of the recontact field is
>the selected date - $tm. So I execute this code:
>
> my $details = InContact::cDBI::contact->contact_detail(recontact => $tm);
> print Dumper $details;
and now I get:
2004/10/05
$VAR1 = bless( {
'_data' => [
{
'id' => '6'
},
{
'id' => '7'
}
],
'_place' => 0,
'_mapper' => [],
'_class' => 'InContact::cDBI::contactdetail'
}, 'Class::DBI::Iterator' );
So now I know which are the contactdetail records involved, but what I
really need is an iterator that will iterate over the contact records.
Am I heading in the right direction?
..john
>What I get is:
>
>2004/10/05
>Tk::Error: Can't select for InContact::cDBI::contactdetail using 'SELECT
>FROM contact contact, contactdetail contactdetail
>WHERE contactdetail.contact_id = contact.id AND recontact = ?
>' (SearchSQL): DBD::mysql::st execute failed: You have an error in your
>SQL syntax. Check the manual that corresponds to your MySQL
> server version for the right syntax to use near 'FROM contact contact,
> contactdetail contactdetail
>WHERE cont [for Statement "SELECT
>FROM contact contact, contactdetail contactdetail
>WHERE contactdetail.contact_id = contact.id AND recontact = ?
>"] at D:/Perl/site/lib/DBIx/ContextualFetch.pm line 51.
>
>
|
Re: Problem with has_many and searching
John Day 16:20 on 05 Oct 2004
|