[Dbix-class] DBIx::Class::Ordered changes.

Peter Rabbitson rabbit+dbic at rabbit.us
Wed Sep 19 10:34:34 GMT 2012


On Tue, Sep 18, 2012 at 04:55:01PM -0700, Bill Moseley wrote:
> The Ordered component for a DELETE operation used to change the "position"
> of the deleted item to zero (moving it out of the way) then move all larger
> positions down one in a series.  If deleting "delete_postion":
> 
> update ordered_list set position = 0 where position = delete_position;
> for cur_position ( delete_position + 1 .. last_position ) {
>     update ordered_list SET postion = position - 1 where position =
> cur_position;
> }
> 
> 
> The current DBIC does this:
> 
> 
> BEGIN WORK
> SELECT me.position FROM ordered_list me WHERE ( ( position > ? AND (
> position != ? AND owner = ? ) ) ) ORDER BY position DESC LIMIT ?: '12',
> '12', '1163299', '1'
> UPDATE ordered_list SET position = ? WHERE ( id = ? ): '0', '8332465'
> UPDATE ordered_list SET position = position - 1 WHERE ( ( ( position
> BETWEEN ? AND ? ) AND owner = ? ) ): '13', '18', '1163299'
> ROLLBACK
> 
> 
> The problem, of course, is I have a UNIQUE( position, owner ) and that last
> update isn't guaranteed to work in order (from 13 to18 -- which would
> prevent duplicate key errors).

The assumption was that databases are able to handle this correctly. Please 
revert the patch[1] removing this functionality (as per its commit message) 
and let us know if this solves your problem. Also I'd recommend filing an RT
bugreport to keep track of this.

Cheers

[1] http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/DBIx-Class.git;a=commitdiff;h=5e6fde33e5a4



More information about the DBIx-Class mailing list