hasOne

Usage

import { Model } from 'pinia-orm'
import Phone from './Phone'
class User extends Model {
  static entity = 'users'
  static fields () {
    return {
      id: this.attr(null),
      name: this.string(''),
      phone: this.hasOne(Phone, 'userId')
    }
  }
}

With Decorator

import { Model } from 'pinia-orm'
import { Attr, HasOne, Str } from 'pinia-orm/decorators'
import Phone from './Phone'
class User extends Model {
  static entity = 'users'
  
  @Attr(null) declare id: number | null
  @Str('') declare name: string
  @HasOne(() => Phone, 'userId') declare phone: Phone
}

Typescript Declarations

function hasOne(
  related: typeof Model,
  foreignKey: string | string[],
  localKey?: string | string[],
): HasOne