Find all records with at least one child in rails
### Find all records with at least one child
Parent.join(:children).uniq.all
# or
Parent.includes(:children).where ("children.id IS NOT NULL")
# or Rails 5
Parent.left_outer_joins(:children ).where.not(children: {id: nil})
### Find all records with no children
Parent.includes(:children).where (children: {id: nil})
# or Rails 5
Parent.left_outer_joins(:children ).where(children: {id: nil})
Influx Infotech is Web Designing Company in India with the team of Expert Web Designers. We are developing Websites Website Design Company in India which loved by our clients.
ReplyDeleteWeb Design Agra
www.influxinfotech.com