<p dir="auto">This is a weird one.  I've tested this with both the client cookie and doctrine provider and the outcome is the same.</p>
<p dir="auto">I've implemented "Remember Me" login functionality for our application.</p>
<p dir="auto">I also have an AuthenticationListener implemented which updates the 'User' entity with a 'lastLogin' DateTime:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    public function onAuthenticationSuccess( AuthenticationEvent $event )
    {
        $user = $event-&gt;getAuthenticationToken()-&gt;getUser();

        if( $user instanceof \Veromo\Bundle\CoreBundle\Entity\User )
        {
            $user-&gt;set( 'lastLogin', new \DateTime() );

            $this-&gt;manager-&gt;flush();
        }
    }"><pre class="notranslate">    <span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">onAuthenticationSuccess</span>( <span class="pl-smi"><span class="pl-smi">AuthenticationEvent</span></span> <span class="pl-s1"><span class="pl-c1">$</span>event</span> )
    {
        <span class="pl-s1"><span class="pl-c1">$</span>user</span> = <span class="pl-s1"><span class="pl-c1">$</span>event</span>-&gt;<span class="pl-en">getAuthenticationToken</span>()-&gt;<span class="pl-en">getUser</span>();

        <span class="pl-k">if</span>( <span class="pl-s1"><span class="pl-c1">$</span>user</span> instanceof \<span class="pl-v">Veromo</span>\<span class="pl-v">Bundle</span>\<span class="pl-v">CoreBundle</span>\<span class="pl-v">Entity</span>\<span class="pl-v">User</span> )
        {
            <span class="pl-s1"><span class="pl-c1">$</span>user</span>-&gt;<span class="pl-en">set</span>( <span class="pl-s">'lastLogin'</span>, <span class="pl-k">new</span> \<span class="pl-v">DateTime</span>() );

            <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">manager</span>-&gt;<span class="pl-en">flush</span>();
        }
    }</pre></div>
<p dir="auto">My 'User' Entity is associated with a 'Contact' Entity with a OneToOne Relationship which is cascaded.</p>
<p dir="auto"><strong>NOW ...</strong></p>
<p dir="auto">When this code executes on an interactive login (user physically enters username and password), all is well - everything goes off without a hitch.</p>
<p dir="auto">When this code executes on a non-interactive login (user has selected 'Remember Me' has a valid cookie, etc ..), it all falls in a heap.</p>
<p dir="auto">It appears that when the <code class="notranslate">flush</code> command executes, Doctrine has 'forgotten' about the relationship that exists between the 'User' Entity and the 'Contact' Entity and attempts to re-create them (opting for an INSERT rather than an UPDATE on <code class="notranslate">flush</code>):</p>
<blockquote>
<ol dir="auto">
<li>INFO - Matched route "adminimiser_home".</li>
<li>DEBUG - Remember-me cookie detected.</li>
<li>DEBUG - SELECT u0_.id AS id0, u0_.email AS email1, u0_.mobile AS mobile2, u0_.username AS username3, u0_.password AS password4, u0_.change_password AS change_password5, u0_.validated AS validated6, u0_.is_blocked AS is_blocked7, u0_.hash AS hash8, u0_.created AS created9, u0_.updated AS updated10, u0_.last_login AS last_login11, u0_.timezone AS timezone12, u0_.contact_id AS contact_id13 FROM <code class="notranslate">user</code> u0_ WHERE u0_.username = ? OR u0_.email = ?</li>
<li>DEBUG - SELECT t0.id AS id3, t0.full_name AS full_name4, t0.created AS created5, t0.updated AS updated6, t0.account_id AS account_id7, t0.type, t1.abn AS abn8, t2.title AS title9, t2.first_name AS first_name10, t2.middle_name AS middle_name11, t2.last_name AS last_name12, t2.gender AS gender13 FROM contact t0 LEFT JOIN contact_business t1 ON t0.id = t1.id LEFT JOIN contact_person t2 ON t0.id = t2.id WHERE t0.id = ?</li>
<li>INFO - Remember-me cookie accepted.</li>
<li>DEBUG - "START TRANSACTION"</li>
<li>DEBUG - INSERT INTO log (date_time, channel, level, ip_address, session_id, message, context) VALUES (?, ?, ?, ?, ?, ?, ?)</li>
<li>DEBUG - "COMMIT"</li>
<li>DEBUG - SELECT t0.id AS id1, t0.roles AS roles2, t0.is_active AS is_active3, t0.account_id AS account_id4, t0.user_id AS user_id5 FROM user_account t0 WHERE t0.user_id = ?</li>
<li>DEBUG - "START TRANSACTION"</li>
<li>DEBUG - INSERT INTO contact (full_name, created, updated, account_id, type) VALUES (?, ?, ?, ?, ?)</li>
<li>DEBUG - INSERT INTO contact_person (id, title, first_name, middle_name, last_name, gender) VALUES (?, ?, ?, ?, ?, ?)</li>
<li>DEBUG - INSERT INTO <code class="notranslate">user</code> (email, mobile, username, password, change_password, validated, is_blocked, hash, created, updated, last_login, timezone, contact_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)</li>
<li>DEBUG - "ROLLBACK"</li>
<li>CRITICAL - Uncaught PHP Exception Doctrine\DBAL\DBALException: "An exception occurred while executing 'INSERT INTO <code class="notranslate">user</code> (email, mobile, username, password, change_password, validated, is_blocked, hash, created, updated, last_login, timezone, contact_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["testuser@blah", null, null, "1MKVMPQp5ODniTDDt2PlGIlMGR9C1ZlLzYo/Y/2LMneA4yU3lVJ1oA==", 0, 1, 0, "c590db7b8cac19accae613f2ead63da1", "2016-01-25 04:21:40", "2016-01-25 04:21:40", "2016-01-26 00:06:40", null, 18]: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'testuser@blah' for key 'UNIQ_8D93D649E7927C74'" at /var/veromo/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 91</li>
</ol>
</blockquote>
<p dir="auto">As you can see - the AUTHENTICATION is fine ... there's no issue there.</p>
<p dir="auto">I've tried everything - including re-associating the contact with the user before the <code class="notranslate">flush</code> - but it appears that <strong>the association is lost after this point</strong>.  And again - only when the <code class="notranslate">RememberMeToken</code> comes into play.</p>
<p dir="auto"><strong>Symfony version(s) affected</strong>: 4.2</p>
<p dir="auto"><strong>Description</strong></p>
<p dir="auto">After clicking <code class="notranslate">Settings</code> in the profiler menu</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Uncaught TypeError: Cannot set property 'checked' of null"><pre class="notranslate"><code class="notranslate">Uncaught TypeError: Cannot set property 'checked' of null
</code></pre></div>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/javiereguiluz/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/javiereguiluz">@javiereguiluz</a></p>