Mongoid support

Depend a bit less on ActiveRecord specifics to support Mongoid.