Find record whose field 'name' not contained within any other record
- by charlie
I have a model Foo with a String bar and a String name. Some records' bar contain the name of other records in them. This is intentional.
I want to find the "root Foo" records - that is, the ones where their name do not appear in the bar records of any other Foo records.
Example:
Foo
id: 1
name: 'foo1'
bar: 'something something'
id: 2
name: 'foo2'
bar: 'foo1 something'
id: 3
name: 'foo3'
bar: 'foo1, foo4'
My method root_foos would return foo2 and foo3 since their names do not appear in any bar string.
edit: I don't want to use a relation or foreign key here - just this method.