[jifty-devel] Jifty::DBI::Collection->unlimit
Jesse Vincent
jesse at bestpractical.com
Sat Jul 28 19:28:25 EDT 2007
On Jul 27, 2007, at 1:35 AM, Mikko Lipasti wrote:
> Hello list,
>
>
> There seems to be a gap between what unlimit does and what the
> documentation says it does.
>
> http://search.cpan.org/dist/Jifty-DBI/lib/Jifty/DBI/
> Collection.pm#unlimit:
> "Clears all restrictions and causes this object to return all rows
> in the primary table."
>
> In reality, unlimit calls clean_slate() which does a whole lot more
> than just removes limits. For instance, it resets order_by().
>
> A doc fix would suffice for me, however I find it a bit unfortunate
> that an unlimit() call doesn't just undo limit() calls as the names
> (and to an extent, current documentation) would imply.
>
Can you test out this patch and tell me if does what you want? It
improves the "unlimit" documentation and adds a new "find_all_rows'
method that has the semantics (I think) you want.
--- lib/Jifty/DBI/Collection.pm (revision 60775)
+++ lib/Jifty/DBI/Collection.pm (local)
@@ -423,8 +423,12 @@
=head2 _is_limited
If we've limited down this search, return true. Otherwise, return
-false.
+false.
+C<1> means "we have limits"
+C<-1> means "we should return all rows. We want no where clause"
+C<0> means "no limits have been applied yet.
+
=cut
sub _is_limited {
@@ -450,7 +454,7 @@
my $query_string = $self->_build_joins . " ";
- if ( $self->_is_limited ) {
+ if ( $self->_is_limited == 1 ) {
$query_string .= $self->_where_clause . " ";
}
if ( $self->distinct_required ) {
@@ -614,7 +618,7 @@
my $query_string = $self->_build_joins . " ";
- if ( $self->_is_limited ) {
+ if ( $self->_is_limited == 1 ) {
$query_string .= $self->_where_clause . " ";
}
@@ -829,8 +833,11 @@
=head2 unlimit
-Clears all restrictions and causes this object to return all
-rows in the primary table.
+Unlimit clears all restrictions on this collection and resets
+it to a "default" pristine state. Note, in particular, that
+this means C<unlimit> will erase ordering and grouping
+metadata. To find all rows without resetting this metadata,
+use the C<find_all_rows> method.
=cut
@@ -841,6 +848,19 @@
$self->_is_limited(-1);
}
+=head2 find_all_rows
+
+C<find_all_rows> instructs this collection class to return all rows in
+the table. (It removes the WHERE clause from your query).
+
+=cut
+
+
+sub find_all_rows {
+ my $self = shift;
+ $self->_is_limited(-1);
+}
+
=head2 limit
Takes a hash of parameters with the following keys:
>
> - Mikko
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://lists.bestpractical.com/pipermail/jifty-devel/attachments/20070728/24debbaf/PGP.pgp
More information about the jifty-devel
mailing list