[Catalyst-commits] r8243 -
CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Model
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Thu Aug 21 11:52:16 BST 2008
Author: karpet
Date: 2008-08-21 11:52:16 +0100 (Thu, 21 Aug 2008)
New Revision: 8243
Modified:
CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Model/RDBO.pm
Log:
add support for has_relationship()
Modified: CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Model/RDBO.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Model/RDBO.pm 2008-08-21 10:50:33 UTC (rev 8242)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Model/RDBO.pm 2008-08-21 10:52:16 UTC (rev 8243)
@@ -308,24 +308,43 @@
sub _get_rel_meta {
my ( $self, $obj, $rel_name ) = @_;
- my $rel = $obj->meta->relationship($rel_name)
+ my $rel = $self->has_relationship( $obj, $rel_name )
or $self->throw_error("no such relationship $rel_name");
- my $map_class = $rel->map_class;
- my $mcm = $map_class->meta;
- my @map_to = $mcm->relationship( $rel->map_to )->column_map;
- my @map_from = $mcm->relationship( $rel->map_from )->column_map;
- my %m = (
- map_to => \@map_to,
- map_from => \@map_from,
- map_class => $map_class,
- );
+ if ( $rel->isa('Rose::DB::Object::Metadata::Relationship::ManyToMany') ) {
- #carp dump \%m;
+ my $map_class = $rel->map_class;
+ my $mcm = $map_class->meta;
+ my @map_to = $mcm->relationship( $rel->map_to )->column_map;
+ my @map_from = $mcm->relationship( $rel->map_from )->column_map;
+ my %m = (
+ map_to => \@map_to,
+ map_from => \@map_from,
+ map_class => $map_class,
+ );
- return \%m;
+ #carp dump \%m;
+
+ return \%m;
+
+ }
+ else {
+ $self->throw_error( "unsupport relationship type: " . ref($rel) );
+ }
}
+=head2 has_relationship( I<obj>, I<rel_name> )
+
+Returns the Rose::DB::Object::Metadata::Relationship instance
+for I<rel_name> if it exists, or undef if it does not.
+
+=cut
+
+sub has_relationship {
+ my ( $self, $obj, $rel_name ) = @_;
+ return $obj->meta->relationship($rel_name);
+}
+
sub add_related {
my ( $self, $obj, $rel_name, $fk_val ) = @_;
my $addmethod = 'add_' . $rel_name;
More information about the Catalyst-commits
mailing list