recreating rails ActiveRecord