How to apply lock on particular column in ruby on rails? -


how apply lock on particular field same number not generate again.

  • i have created algoritham in create string using year+000..+integer number example : "20150001","20150002","20150003" etc.

  • the problem when multiple user request number @ time same number generated.

following function call

def get_algo_number(model_name,prefix) <br>   year = get_year    if model_name.count > 0       last_number = model_name.last.number      if last_number[2..5].to_i > year.to_i       return create_number(year,prefix)     else       # if letest generated number exist generate new number          return last_number.next      end   else     return create_number(year,prefix)   end end 

please if have solution regarding apply lock. thanks

yes, resolved problem using multi-threading.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -