title: TypeOrm save method not updating object
body: <p>Consider this entity:</p>
  <pre class="lang-js prettyprint-override"><code>// account.ts
  import { Entity, PrimaryGeneratedColumn, PrimaryColumn, Column, BaseEntity, Index, CreateDateColumn,  UpdateDateColumn, OneToOne, JoinColumn } from 'typeorm'
  
  @Entity()
  export class Account extends BaseEntity {
    @PrimaryGeneratedColumn()
    id: number
  
    @Column({ length: 50, unique: true })
    @Index({ unique: true })
    accountIdentifier: string
  
    @Column({ nullable: true, length: 100 })
    name?: string
  }
  </code></pre>
  <p>To save a new <code>account</code> or return an existing <code>account</code> we have this working code:</p>
  <pre class="lang-js prettyprint-override"><code>const knownAccount = await Account.findOne({ accountIdentifier: token.oid })
  if (knownAccount) return done(null, knownAccount, token)
  
  const account = new Account()
  account.accountIdentifier = token.oid
  account.name = token.name
  account.userName = (token as any).preferred_username
  const newAccount = await account.save()
  return done(null, newAccount, token)
  </code></pre>
  <p>In <a href="https://typeorm.io/#/repository-api" rel="noreferrer">the docs</a> it says:</p>
  <blockquote>
  <p>save - Saves a given entity or array of entities. If the entity already exist in the database, it is updated. If the entity does not exist in the database, it is inserted. It saves all given entities in a single transaction (in the case of entity, manager is not transactional). Also supports partial updating since all undefined properties are skipped. Returns the saved entity/entities.</p>
  </blockquote>
  <p>So we would expect this code to work and replace the previous code but it does not seem to update the row but rather complains about inserting a duplicate key:</p>
  <pre class="lang-js prettyprint-override"><code>const account = await Account.save({
     accountIdentifier = token.oid,
     name = token.name,
     userName = (token as any).preferred_username,
  })
  return done(null, account, token)
  </code></pre>
  <p>The IDE does show it will update or insert but it does not update:
  <a href="https://i.stack.imgur.com/X7wRy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/X7wRy.png" alt="enter image description here" /></a></p>
  <p>How is it possible to use the <code>save</code> method correctly? So it adds an account if it doesn't exist and/or updates the account when it's already there.</p>