public function validate($groups = null, $fields = null, $exclude_fields = null, $exclude_types = null) { if (parent::validate($groups, $fields, $exclude_fields)) { $qb = static::select('item.id, item.code')->where("item.code = '{$this->code}'"); if (isset($this->id)) { $qb->andWhere("item.id != {$this->id}"); } // Throw an error if there are other languages set to this if (count($qb->getQuery()->getArrayResult()) > 0) { $this->addErrorForField('code', 'This language has already been added!'); } return count($this->errors) === 0; } return false; }