Reimpl of part of ActiveRecord