Skip to content

Instantly share code, notes, and snippets.

@oniryx
Created May 9, 2012 08:25
Show Gist options
  • Save oniryx/2642948 to your computer and use it in GitHub Desktop.
Save oniryx/2642948 to your computer and use it in GitHub Desktop.
Init sortable_rank when using propel with sortable behavior
/* Init sortable_rank without scope */
select @rank:=0;
update TABLE_NAME set sortable_rank=(@rank:=(@rank+1));
/* Init sortable_rank with scope */
select @range:=0;
update TABLE_NAME set sortable_rank=IF(@range!=SCOPE_COLUMN, @rank:=1 && (@range:=SCOPE_COLUMN), @rank:=@rank+1) order by SCOPE_COLUMN, PK_COLUMN;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment