searching through has_many, how?

[prev] [thread] [next] [Date index for 2004/07/02]

From: Rhesa Rozendaal
Subject: searching through has_many, how?
Date: 12:59 on 02 Jul 2004
I have a conceptual hurdle to take. I think I have a basic understanding 
of most of CDBI's features, but I am stuck on this one.

I have two tables, Table1, Table2, with a linking table LinkTable.
Relationships are defined as:

    Table1->has_many(table2s => [LinkTable => 'table2']);

    Table2->has_many(table1s => [LinkTable => 'table1']);

    LinkTable->has_a(table1 => 'Table1');
    LinkTable->has_a(table2 => 'Table2');

So far this is standard. Correct me if I'm wrong.

Now my problem:
I have an object for Table1, $table1.
I want to know if it has any Table2s with somefield2 = 'somevalue'.
I know I can do
    $table2 = Table2->retrieve(somefield2 => 'somevalue');
    $table1->table2s($table2);

What if my criteria for Table2 instances are broader?
I can't do
    $table1->table2s( somefield2 => 'somevalue' );
because somefield2 is not a field of LinkTable.

What _can_ I do?


Rhesa Rozendaal

searching through has_many, how?
Rhesa Rozendaal 12:59 on 02 Jul 2004

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