mysql - how do I check whether user exists in db or not -


in rails application, have relationship setup such has user has_many :contacts, contacts of user stored in contacts

when user.contacts contacts of current_user wanted check how many of user contacts registered meaning existing in users table. have solution in mind comparing of each contact of user db(users table). process time consuming looking more optimized way.

assuming contact model has email attribute , user has email attribute. find number of users registered emails contacts of current_user, do:

contact_emails = current_user.contacts.pluck("contacts.email") no_of_users_registered = user.where(email: contact_emails).count 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -