[CDBI] has_a and null foreign keys
Michael G Schwern
schwern at pobox.com
Tue Apr 10 13:03:50 BST 2007
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?
More information about the ClassDBI