Add missing require for AR 3.1 and uniq => distinct
Merge elements from spectator's pull request
Merge further elements from spectator's Rails 3 comptability work, merge pull request #208 from pdf/reorder, use Rails 4 active-record distinct method which replaces uniq