Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value setted to null on flush doctrine

I've got a problem with my code. I am just trying to insert a simple set of data to my db, but doctrine insert my attribute (telVerifCode) as NULL.

I've dumped my data and figured out, that attribute (telVerifCode) has some value in it, but after I flush it is set to NULL.

This is my controller:

$user = $this->getUser();

if ($user->getTel() != $tel || $user->getTelCode() != $telCode) {

    try {
        $code = $this->sendTelehopneCode($user);
    } catch (\Exception $e) {
        //.......
    }

    // update user phone verifcation fields //
    $user->setTelVerifCode($code);
    $user->setLastTelVerificationCodeDate(new \DateTime());

    $em->persist($user);
    $em->flush();
}

My ORM Mapping:

/**
 * @var string
 *
 * @ORM\Column(name="tel_verification_code", type="string", length=255, nullable=true)
 */
protected $telVerifCode;
/**
 * @var \DateTime
 *
 * @ORM\Column(name="last_tel_verification_code_date", type="date", nullable=true)
 */
protected $lastTelVerificationCodeDate;

sendTelehopneCode function :

private function sendTelehopneCode($user)
{
    $code = strval(rand(100000, 999999));
    $tel = $user->getTelCode() . $user->getTel();
    $msg = 'code:' . $code;

    $twilio = $this->get('twilio.api');
    try {
        $message = $twilio->account->messages->sendMessage(
            "+14*******", // Verified Outgoing Caller ID or Twilio number
            $tel, // The phone number you wish to send a message to
            $msg
        );
    } catch (\Services_Twilio_RestException $e) {
        throw $e;
    }

    return $code;
}
like image 717
ghaziksibi Avatar asked Dec 06 '25 03:12

ghaziksibi


2 Answers

Try clearing your doctrine caches, the code looks fine and cannot be the issue.

./bin/console doctrine:cache:clear-metadata
./bin/console doctrine:cache:clear-query
./bin/console doctrine:cache:clear-result
like image 139
Samir Patel Avatar answered Dec 07 '25 17:12

Samir Patel


I solved the problem, I made a listener On preUpdate one that puts the value null, I completely forgotten it :(

like image 41
ghaziksibi Avatar answered Dec 07 '25 17:12

ghaziksibi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!