Posts

Showing posts from July, 2019

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 } )