Find all records with at least one child in rails
### Find all records with at least one child
Parent.join(:children).uniq.al l
# or
Parent.includes(:children).whe re("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).whe re(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