[Catalyst-commits] r14527 - in CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk: . lib/CatalystX/CRUD/Model lib/CatalystX/CRUD/Object
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Tue May 13 05:01:57 GMT 2014
Author: karpet
Date: 2014-05-13 05:01:57 +0000 (Tue, 13 May 2014)
New Revision: 14527
Modified:
CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Model/RDBO.pm
CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Object/RDBO.pm
Log:
fix find_related() bug for 1-to-many rels
Modified: CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/Changes 2014-05-12 20:20:09 UTC (rev 14526)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/Changes 2014-05-13 05:01:57 UTC (rev 14527)
@@ -1,5 +1,9 @@
Revision history for CatalystX-CRUD-Model-RDBO
+0.302 xxx
+ - fix bug in find_related() where foreign table column name assumed to be
+ same as local table, esp for one-to-many relationships
+
0.301 10 May 2014
- skip related sort_by unless explicitly passed in cxc-* params
(fix for 0.29 r14454)
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 2014-05-12 20:20:09 UTC (rev 14526)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Model/RDBO.pm 2014-05-13 05:01:57 UTC (rev 14527)
@@ -8,7 +8,7 @@
use Carp;
use Data::Dump qw( dump );
-our $VERSION = '0.301';
+our $VERSION = '0.302';
__PACKAGE__->mk_ro_accessors(
qw( name manager treat_like_int load_with related_load_with ));
@@ -376,12 +376,34 @@
sub find_related {
my ( $self, $obj, $rel, $foreign_pk_value ) = @_;
+ my $relationship = $self->has_relationship( $obj, $rel )
+ or $self->throw_error("no relationship for $rel");
my $method = 'find_' . $rel;
- my $meta = $self->_get_rel_meta( $obj, $rel );
- my $fpk = $meta->{map_to}->[1];
- my $args = [ $fpk => $foreign_pk_value ];
- my $r = $obj->$method( query => $args );
+ my $args;
+ if ($relationship->isa(
+ 'Rose::DB::Object::Metadata::Relationship::ManyToMany')
+ )
+ {
+ my $meta = $self->_get_rel_meta( $obj, $rel );
+ $args = [ $meta->{map_to}->[1] => $foreign_pk_value ];
+ }
+ else {
+ # all the PKs and Unique cols for the foreign class, OR'd together.
+ my $pk_cols = $relationship->class->meta->primary_key_column_names;
+ my $uniq_cols = [ map {@$_}
+ @{ $relationship->class->meta->unique_keys_column_names } ];
+ $args = [
+ or => [
+ map { $_ => $foreign_pk_value } ( @$pk_cols, @$uniq_cols )
+ ]
+ ];
+ }
+
+ #dump $args;
+
+ my $r = $obj->$method( query => $args );
+
# save ourselves lots of method-call overhead.
my $class = $self->object_class;
Modified: CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Object/RDBO.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Object/RDBO.pm 2014-05-12 20:20:09 UTC (rev 14526)
+++ CatalystX-CRUD/CatalystX-CRUD-Model-RDBO/trunk/lib/CatalystX/CRUD/Object/RDBO.pm 2014-05-13 05:01:57 UTC (rev 14527)
@@ -7,7 +7,7 @@
use Rose::DB::Object::Helpers qw( column_values_as_json );
use JSON;
-our $VERSION = '0.301';
+our $VERSION = '0.302';
=head1 NAME
More information about the Catalyst-commits
mailing list