X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FOrdered.pm;h=8e2c74dc2786214eff7dd6f8fc3a35ce1b414961;hb=dd3583f282f6807ac7857c2d6b7a3ddd85a11ab4;hp=f721c69617f477d88fb09b6a36e02a8edb643810;hpb=fe82b6cf92f6dfd891c90c7e28bcffd9966b039b;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Ordered.pm b/lib/DBIx/Class/Ordered.pm index f721c69..8e2c74d 100644 --- a/lib/DBIx/Class/Ordered.pm +++ b/lib/DBIx/Class/Ordered.pm @@ -279,20 +279,18 @@ sub move_to { my $from_position = $self->get_column( $position_column ); return 0 if ( $to_position < 1 ); return 0 if ( $from_position==$to_position ); + my @between = ( + ( $from_position < $to_position ) + ? ( $from_position+1, $to_position ) + : ( $to_position, $from_position-1 ) + ); my $rs = $self->result_source->resultset->search({ - -and => [ - $position_column => - { -between => [ $from_position, $to_position ] }, - ], + $position_column => { -between => [ @between ] }, $self->_grouping_clause(), }); my $op = ($from_position>$to_position) ? '+' : '-'; - 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 ); + $rs->update({ $position_column => \"$position_column $op 1" }); + $self->update({ $position_column => $to_position }); return 1; } @@ -353,6 +351,15 @@ __END__ =head1 BUGS +=head2 Unique Constraints + +Unique indexes and constraints on the position column are not +supported at this time. It would be make sense to support them, +but there are some unexpected database issues that make this +hard to do. The main problem from the author's view is that +SQLite (the DB engine that we use for testing) does not support +ORDER BY on updates. + =head2 Race Condition on Insert If a position is not specified for an insert than a position @@ -369,7 +376,7 @@ you've pre-loaded the objects then when you move one of the objects the position of the other object will not reflect their new value until you reload them from the database. -The are times when you will want to move objects as groups, such +There are times when you will want to move objects as groups, such as changeing the parent of several objects at once - this directly conflicts with this problem. One solution is for us to write a ResultSet class that supports a parent() method, for example. Another