public function findAndLoadPossibleDuplicateEntityByFields(array $check_fields)
    {
        $class_name = \get_class($this) . self::CLASS_RELATION_NAME_REPOSITORY;
        /** @var EntityRepository $repo */
        $repo = new $class_name;

        $params = [];
        foreach ($check_fields as $field) {
            $method = 'get' . ucfirst($field);
            $params[$field] = $this->$method();
        }

        $existing_entry = $repo::findOneEntityByCriteria($params);

        if ($existing_entry) {
            $this->setId($existing_entry->getId(), false);
        }

        return $this;
    }
public function findAndLoadPossibleDuplicateEntityByFields(array $check_fields)
    {
        $class_name = \get_class($this) . self::CLASS_RELATION_NAME_REPOSITORY;
        /** @var EntityRepository $repo */
        $repo = new $class_name;

        $params = [];
        foreach ($check_fields as $field) {
            $method = 'get' . ucfirst($field);
            $params[$field] = $this->$method();
        }

        $existing_entry = $repo::findOneEntityByCriteria($params);

        if ($existing_entry) {
            $this->setId($existing_entry->getId(), false);
        }

        return $this;
    }
public function findAndLoadPossibleDuplicateEntityByFields ( array $ check_fields ) { $ class_name = \ get_class ( $ this ) . self :: CLASS_RELATION_NAME_REPOSITORY ; /** @var EntityRepository $repo */ $ repo = new $ class_name ; $ params = [ ] ; foreach ( $ check_fields as $ field ) { $ method = 'get' . ucfirst ( $ field ) ; $ params [ $ field ] = $ this -> $ method ( ) ; } $ existing_entry = $ repo :: findOneEntityByCriteria ( $ params ) ; if ( $ existing_entry ) { $ this -> setId ( $ existing_entry -> getId ( ) , false ) ; } return $ this ; }
If possible to find existing entry by all this fields than update but not save new
Make sure to first load data before calling that method

@param array $check_fields that must be unique
@return $this
If possible to find existing entry by all this fields than update but not save new Make sure to first load data before calling that method