title: Sequelize Typescript create object with associations
body: <p>I'm trying to build a new instance with OneToOne association, according to <a href="https://www.npmjs.com/package/sequelize-typescript" rel="nofollow noreferrer">https://www.npmjs.com/package/sequelize-typescript</a></p>
  <p>models/measure.ts :</p>
  <pre><code>@Table({ tableName: &quot;measure&quot; })
  export class Measure extends Model {
      ...
  
      // Token
      @ForeignKey(() =&gt; Token)
      @Column({ type: DataType.INTEGER, allowNull: false, unique: true })
      id_token!: number
  
      @BelongsTo(() =&gt; Token)
      token!: Token
  }
  </code></pre>
  <p>models/token.ts :</p>
  <pre><code>@Table({ tableName: &quot;token&quot; })
  export class Token extends Model {
      ...
  
      // Measure
      @HasOne(() =&gt; Measure)
      measure: Measure
  }
  </code></pre>
  <p>my sequelize instance :</p>
  <pre><code>export const sequelize: Sequelize = new Sequelize({
      ...
      repositoryMode: true,
  })
  sequelize.addModels([Token, Measure])
  
  export const tokenRepository = sequelize.getRepository(Token)
  export const measureRepository = sequelize.getRepository(Measure)
  </code></pre>
  <p>now i want to create a new Measure instance, with an existing Token :</p>
  <pre><code>const token = await tokenRepository.findOne({where: {value: value}})
  ...
  console.log(token.isNewRecord) // false
  const measure = measureRepository.build({...params, token: token}, {include: [{model: tokenRepository}]})
  console.log(measure.token.isNewRecord) // true
  
  await measure.save() // it try to insert an new token here
  </code></pre>
  <p>Sequelize try to insert a new token instead of insert only the measure. Where is my mistake ?</p>