stefankroes/ancestry — pull request #194 by chendrix (2014-07-16 18:16:28+00:00)
Title: Update roots scope to look for null or empty ''

I updated the roots scope to not only look for a null ancestry column but
to also look for one which has the empty string (''). This feature came
about because of a project I'm working on where I don't control the
database, i.e. I don't have write/amend rights to the db, so I forced
them to make an `ancestry` column that follows materialized path, so I
could use the ancestry gem even for its read-only methods.

However, when they implemented it, they also created empty strings
instead of NULL columns for root nodes. This *should* be considered a
valid representation of a root node, along with a NULL column.

Because plain ActiveRecord does not deal with ORs in their queries well,
I am using plain arel. I added a convenience method to refer to the
arel_table definition of the ancestry_column, and construct the
appropriate arel query inside of the where() in the scope.