in reply to Class::DBI - Sorting by key in related table.

Having a similar problem - searching by a field from a related table - I resigned finding a CDBI solution and solved it in the database by creating a view.
  • Comment on Re: Class::DBI - Sorting by key in related table.

Replies are listed 'Best First'.
Re^2: Class::DBI - Sorting by key in related table.
by itub (Priest) on Apr 24, 2005 at 20:57 UTC
    I've had similar problems but tackled them using the lower-level set_sql method in Class::DBI (views weren't available):
    # search for keys in a given building, # issued to persons with a given status IssuedKey->set_sql(building_id_person_status => 'SELECT id FROM IssuedKey, Person WHERE Person.person_id=IssuedKey.person_id AND IssuedKey.building_id=? AND Person.status=?'); my (@keys) = IssuedKey->search_building_id_person_status( $building, $status);

    The example above is not very general because it only searches those specific fields, but sometimes it is all you need.

      For something like this, I would agree that set_sql is a good approach. There are things databases are pretty good at, and I think this is one of them. Note that if you are going to reference columns from another table in a join, you'll need to add them as TEMP columns in the class with the sql code.