Home Is there a way to update a field in rails if same value exists for a different field maintaining its uniqueness?
Reply: 0

Is there a way to update a field in rails if same value exists for a different field maintaining its uniqueness?

user8230
1#
user8230 Published in September 20, 2018, 12:43 pm

I am working on user's model in which users will be sorted on the basis of sort_order for them. What I am trying to achieve is that if we set same sort_order for a new user or update existing user, all users with same sort_order are incremented. For example we have 3 user types with their sort_order as follows


Gold with sort_order as 1

Diamond with sort_order as 2

Platinum with sort_order as 3


Updating Gold to 2 should result in Diamond increasing to 3 and Platinum increasing to 4.

Is there a way to do this in Rails?

share|improve this question
  • What should happen if Diamond changes to 3? And what should happen if Diamond changes to 4? – Pablo Feb 8 at 21:03
  • if Diamond changes to 3,Platinum will be updated to 4(this needs to happen if Gold is still at 2) – Saurabh Feb 8 at 21:18
  • I mean. With your initial data (as you wrote in the question). What would happen in both changes I asked? – Pablo Feb 8 at 21:22
  • That way we will maintain unique sort_order even if user tries to update in any way. – Saurabh Feb 8 at 21:24
  • You are not answering what I asked. I want to know the specific values for Gold, Diamond and Platinum, after both changes. I want to know the operation that must be done after a specific change. – Pablo Feb 8 at 21:27

2 Answers 2

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.38904 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO