[Jifty-commit] r5040 - in Jifty-DBI/branches/tisql: lib/Jifty/DBI t
Jifty commits
jifty-commit at lists.jifty.org
Tue Feb 5 21:18:34 EST 2008
Author: ruz
Date: Tue Feb 5 21:18:34 2008
New Revision: 5040
Modified:
Jifty-DBI/branches/tisql/ (props changed)
Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm
Jifty-DBI/branches/tisql/t/13collection.t
Log:
r4810 at cubic-pc (orig r4809): sartak | 2008-01-11 00:00:15 +0300
r50046 at onn: sartak | 2008-01-10 15:35:07 -0500
Add Collection->add_order_by, which refines ordering, instead of thrashing it
Modified: Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm (original)
+++ Jifty-DBI/branches/tisql/lib/Jifty/DBI/Collection.pm Tue Feb 5 21:18:34 2008
@@ -1485,6 +1485,9 @@
Use array of hashes to order by many columns/functions.
+Calling this I<sets> the ordering, it doesn't refine it. If you want to keep
+previous ordering, use C<add_order_by>.
+
The results would be unordered if method called without arguments.
Returns the current list of columns.
@@ -1506,6 +1509,27 @@
return ( $self->{'order_by'} || [] );
}
+=head2 add_order_by EMPTY|HASH|ARRAY_OF_HASHES
+
+Same as order_by, except it will not reset the ordering you have already set.
+
+=cut
+
+sub add_order_by {
+ my $self = shift;
+ return if $self->derived;
+ if (@_) {
+ my @args = @_;
+
+ unless ( UNIVERSAL::isa( $args[0], 'HASH' ) ) {
+ @args = {@args};
+ }
+ push @{ $self->{'order_by'} ||= [] }, @args;
+ $self->redo_search();
+ }
+ return ( $self->{'order_by'} || [] );
+}
+
=head2 _order_clause
returns the ORDER BY clause for the search.
Modified: Jifty-DBI/branches/tisql/t/13collection.t
==============================================================================
--- Jifty-DBI/branches/tisql/t/13collection.t (original)
+++ Jifty-DBI/branches/tisql/t/13collection.t Tue Feb 5 21:18:34 2008
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 4;
+use Test::More tests => 7;
my $package;
BEGIN {
@@ -87,3 +87,39 @@
is $obj->_order_clause,
' ORDER BY name ASC, sent ASC, ab.msg_session ASC ',
'empty and false aliases';
+
+$obj->add_order_by(
+ {
+ alias => 'ab',
+ column => 'msg_id',
+ order => 'DESC',
+ },
+ {
+ alias => 'main',
+ column => 'yaks',
+ },
+);
+
+is $obj->_order_clause,
+ ' ORDER BY name ASC, sent ASC, ab.msg_session ASC, ab.msg_id DESC, main.yaks ASC ',
+ "add_order_by doesn't thrash previous ordering";
+
+$obj->order_by(
+ alias => 'ab',
+ column => 'msg_id',
+ order => 'DESC',
+);
+
+is $obj->_order_clause,
+ ' ORDER BY ab.msg_id DESC ',
+ "order_by does thrash previous ordering";
+
+$obj->add_order_by(
+ alias => 'main',
+ column => 'yaks',
+);
+
+is $obj->_order_clause,
+ ' ORDER BY ab.msg_id DESC, main.yaks ASC ',
+ "add_order_by works when passing a list-as-hash directly";
+
More information about the Jifty-commit
mailing list