Re: [CDBI] has_a and null foreign keys
Michael G Schwern <[email protected]> Tue, 10 Apr 2007 08:03:50 -0400
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Arshavir Grigorian wrote: > I have 2 tables that are related to each other through has_a > relationship in Class::DBI. However, it can happen that a record in > table1 does not have the foreign key for table2 populated. In this > situation, if I try to call My::Class->retrieve(id => > $id)->foreign_key->column_in_table2(), I get an error because > foreign_key() didn't return a valid object and column_in_table2() fails. > Should I be trying to check whether ->foreign_key() returns a valid > object and only then call column_in_table2() or is there another way? Would might_have() be useful here?