mongoid4 - Rails check for duplicate models -


i did mistake in rails app, , didn't enforce uniqueness of logins. i'd clean mess finding , removing duplicates (manually) in code.

is there nice command enter in rails console let me find duplicates ? eg. find 2 users same login, , maybe make array of array of duplicates ?

assuming model user , looking duplicate attribute login, should able this:

user.find_by_sql("select u1.id, u1.login users u1 left join users u2 u1.login=u2.login , u1.id!=u2.id order u1.login, u1.id") 

of course, can change select include whatever attributes need in order decide duplicates.

edit mongoid, look @ link


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -