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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -