public function getPrimaryKey()
    {
        if (null == $this->primaryKey) {
            foreach ($this->getFields() as $field) {
                if ($field->isPrimaryKey()) {
                    $this->primaryKey = $field;
                    break;
                }
            }
        }
        return $this->primaryKey;
    }