[Catalyst-commits] r8240 -
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Thu Aug 21 06:53:49 BST 2008
Author: karpet
Date: 2008-08-21 06:53:48 +0100 (Thu, 21 Aug 2008)
New Revision: 8240
Modified:
CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm
Log:
support new relationship api
Modified: CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm 2008-08-21 05:53:17 UTC (rev 8239)
+++ CatalystX-CRUD/CatalystX-CRUD-ModelAdapter-DBIC/trunk/lib/CatalystX/CRUD/ModelAdapter/DBIC.pm 2008-08-21 05:53:48 UTC (rev 8240)
@@ -146,7 +146,7 @@
->resultset( $self->_get_moniker( $controller, $c ) )->count(@q);
}
-=head2 make_query( I<controller>, I<context>, I<field_names> )
+=head2 make_query( I<controller>, I<context> [, I<field_names> ] )
Returns an array ref of query data based on request params in I<context>,
using param names that match I<field_names>.
@@ -170,6 +170,49 @@
return $self->make_sql_query($field_names) || {};
}
+=head2 search_related( I<controller>, I<context>, I<obj>, I<relationship> [, I<query> ] )
+
+Implements required method. Returns array ref of
+objects related to I<obj> via I<relationship>. I<relationship>
+should be a method name callable on I<obj>.
+
+=head2 iterator_related( I<controller>, I<context>, I<obj>, I<relationship> [, I<query> ] )
+
+Like search_related() but returns an iterator.
+
+=head2 count_related( I<controller>, I<context>, I<obj>, I<relationship> [, I<query> ] )
+
+Like search_related() but returns an integer.
+
+=cut
+
+sub search_related {
+ my ( $self, $controller, $c, $obj, $rel, $query ) = @_;
+ $query ||= $self->make_query( $controller, $c );
+ my @q = ( $query->{query} );
+ push( @q, $controller->model_meta->{resultset_opts} )
+ if $controller->model_meta->{resultset_opts};
+ return [ $obj->$rel->search(@q) ];
+}
+
+sub iterator_related {
+ my ( $self, $controller, $c, $obj, $rel, $query ) = @_;
+ $query ||= $self->make_query( $controller, $c );
+ my @q = ( $query->{query} );
+ push( @q, $controller->model_meta->{resultset_opts} )
+ if $controller->model_meta->{resultset_opts};
+ return scalar $obj->$rel->search(@q);
+}
+
+sub count_related {
+ my ( $self, $controller, $c, $obj, $rel, $query ) = @_;
+ $query ||= $self->make_query( $controller, $c );
+ my @q = ( $query->{query} );
+ push( @q, $controller->model_meta->{resultset_opts} )
+ if $controller->model_meta->{resultset_opts};
+ return $obj->$rel->count(@q);
+}
+
sub _get_field_names {
my $self = shift;
my $controller = shift;
More information about the Catalyst-commits
mailing list