Various changes to have it work with higher ruby and activerecord versions