From: Matt S Trout Date: Fri, 21 Apr 2006 15:55:20 +0000 (+0000) Subject: Make ordered use CASE (still doesn't pass tests, sigh) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fe82b6cf92f6dfd891c90c7e28bcffd9966b039b;p=dbsrgits%2FDBIx-Class-Historic.git Make ordered use CASE (still doesn't pass tests, sigh) --- diff --git a/lib/DBIx/Class/Ordered.pm b/lib/DBIx/Class/Ordered.pm index ba5514d..f721c69 100644 --- a/lib/DBIx/Class/Ordered.pm +++ b/lib/DBIx/Class/Ordered.pm @@ -281,17 +281,18 @@ sub move_to { return 0 if ( $from_position==$to_position ); my $rs = $self->result_source->resultset->search({ -and => [ - $position_column => { ($from_position>$to_position?'<':'>') => $from_position }, - $position_column => { ($from_position>$to_position?'>=':'<=') => $to_position }, + $position_column => + { -between => [ $from_position, $to_position ] }, ], $self->_grouping_clause(), }); my $op = ($from_position>$to_position) ? '+' : '-'; - $rs->update({ - $position_column => \"$position_column $op 1", - }); - $self->set_column( $position_column => $to_position ); - $self->update(); + my $case_stmt = "CASE $position_column \n". + " WHEN $from_position THEN $to_position\n". + " ELSE $position_column $op 1\n". + "END"; + $rs->update({ $position_column => \$case_stmt }); + $self->store_column( $position_column => $to_position ); return 1; }