Rewriting the ActiveRecord