Last active
August 29, 2015 14:01
-
-
Save goooooouwa/d7d02263b2109869471c to your computer and use it in GitHub Desktop.
active record query to find all companies with no contact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in English: return all companies that have a contact whose id is nil. | |
# why this will work is because the "includes" method will join the two tables( companies and contacts) into one table. | |
# for those companies who has no contacts, the record's contact is null. | |
Company.includes(:contacts).where(contacts: {id: nil}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment