Ref #381. Ported propelorm/propel#618