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
Post a Comment