Just set the column manually right before you persist.  Here's what I did:

if($form->isSubmitted() && $form->isValid()) {
    $em = $this->getEm();

    //Create the user
    $user->setSGuid((new UuidGenerator())->generate($em, null));
    $user->setPlainPassword(self::DEFAULT_PASSWORD);
    $this->getUserManager()->updateUser($user);

    ...

}


The UuidGenerator class is exactly what doctrine uses if you had an @Id 
field with a @GeneratedValue with a strategy of 'UUID'.  In your case it 
calls the following method in Doctrine\DBAL\Platforms\SQLServerPlatform


/**
 * {@inheritDoc}
 */
public function getGuidExpression()
{
    return 'NEWID()';
}




On Tuesday, September 27, 2016 at 8:02:13 AM UTC-5, Dominik Echterbruch 
wrote:
>
> Hi all,
>
> let's assume we have an MSSQL database with a table like this:
> CREATE TABLE foo (
>     id int NOT NULL,
>     rowguid uniqueidentifier(36) DEFAULT (newid()),
>     bar varchar(20),
>     CONSTRAINT PK_foo PRIMARY KEY (id)
> );
>
> I need to insert records into this table and read the value from column 
> bar. When doing this manually, everything is fine:
> INSERT INTO foo (bar) VALUES ('test');
> When reading rowguid from the newly created record, there is a 36-digit 
> value.
>
> But when doing the same thing via a Symfony entity, the column is set to 
> NULL. I tried many different things:
> - removing setter for the column => results in fatal error
> - set strategy to "UUID" => results in id being set to a UUID and rowguid 
> still being set to NULL (which looks very much like a bug)
> - and much more => to no avail
>
> I wonder if there is a possibility to remove the column from the INSERT 
> statement while still being able to SELECT the column.
>
> Any hints on how to accomplish this task?
>
> Best regards,
> Dominik
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to