Oh I see. I misunderstood. If the current setup works, you should keep it.

Albert


On Monday, April 14, 2014 at 5:40 PM, John Morgan wrote:

> In app/controllers/queue_items_controller.rb:
> > end > end > > + def all_queue_positions_valid?(new_queue_values) > + (all_queue_positions_integers?(new_queue_values) && > + all_queue_positions_unique?(new_queue_values)) > + end > + > + def all_queue_positions_integers?(new_queue_values)  
> Really interesting info, thanks for linking it! I will definitely try that out at some point.
> Unless I'm misunderstanding, though, isn't creating a unique index on the database going to still have the same issue as doing a uniqueness validation for position at the model level? (An example of my issue: switching positions of 2 queue items. I can't save queue_item_1 to position 2 when queue_item_2, which hasn't had its position changed yet, currently has position 2.) It seems that unique indexes are to prevent a setup with multiple server processes from evading model-layer uniqueness validation by hitting the model layer around the same time (before either of them has saved to the db), which is obviously really useful but not quite the design problem I have.  
> In other words, my problem is that a model-layer uniqueness validation actually isn't quite permissive enough for this particular condition, but I obviously don't want to bypass validation entirely here.
> Maybe there is a functionality of unique indexes that I'm not picking out?
>  
> —
> Reply to this email directly or view it on GitHub (https://github.com/Nissl/myflix/pull/7/files#r11597412).
>  
>  
>