public function validate() { $return = true; if ($this->user_id == "") { $this->errors[] = "You must enter a user"; $return = false; } if ($this->discount_code_id == "") { $this->errors[] = "You must enter a discount code"; $return = false; } if ($return) { $dcu = DiscountCodeUser::find("users.id = '{$user_id}' AND discount_codes.id = '{$discount_id}'"); if ($dcu && (!$this->id || $this->id != $dcu->id)) { $this->errors[] = 'User has already been added for this discount'; $return = false; } } if (count($this->errors) > 0) { $return = false; } return $return; }