Subject: | relationships |
David,
I was able to get relationships working. I used your $user code from the _tables sub and passed that into the DBI API. The case sensitivity gets a little odd between Oracle (wants uppercase) and DBI (returns keys lower case), but the code below sorts it out nicely, most derivered from CLass::DBI::Loader::Generic::_relationships.
# Find and setup relationships
sub _relationships {
my $self = shift;
foreach my $table ( $self->tables ) {
my $dbh = $self->find_class($table)->db_Main;
my $user = uc $self->{_datasource}->[1];
# handle user strings of the form user@sid or user/password@sid
# we want only the user (schema) name
$user =~ s/^(\w+)[@\/]?.*$/$1/;
if (my $sth = $dbh->foreign_key_info( undef, $user, undef
, undef, $user, uc($table)) ) {
for my $res ( @{ $sth->fetchall_arrayref( {} ) } ) {
my $column = lc($res->{FK_COLUMN_NAME} || $res->{fk_column_name}); # these are usually lower case, depending on the DBI/Oracle driver
my $other = lc($res->{UK_TABLE_NAME} || $res->{uk_table_name});
eval { $self->_has_a_many( $table, $column, $other ) };
warn qq/has_a_many failed "$@"/ if $@ && $self->debug;
}
}
}
}