This reminds me of another recent topic: https://groups.google.com/forum/?fromgroups#!topic/rubyonrails-core/wAkJbUb3mio They're discussing the idea of adding a presence scope with `Person.where.present(:name)` If this method also checks for the presence of associated records like `Person.where.present(:parent)` then it would make sense to also have a method that does the opposite (like you're proposing). Or perhaps it would simply make more sense to instead use `Person.where.not.present(:parent)`.
On Monday, December 10, 2018 at 7:55:51 PM UTC-6, John Pollard wrote: > > I definitely find myself looking for orphans to clean up my database. What > about adding a method scope as "missing_#{relationship_name}" > > Book.missing_author #without a parent > > Author.missing_books #without children > > > On Tuesday, November 27, 2018 at 5:41:53 PM UTC-5, Tom Rossi wrote: >> >> Its common for me to look for orphans and I typically do it like this: >> >> Child.eager_load(:parent).where(parents: { id: nil }) >> >> I would like to propose putting together a PR for something like this: >> >> Child.missing(:parent) >> Parent.missing(:children) >> >> Please let me know if others are interested in the functionality and I >> would love to give it a shot! >> > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.