belongsTo

Usage

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

With Decorator

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

Typescript Declarations

function belongsTo(
  related: typeof Model,
  foreignKey: string | string[],
  ownerKey?: string | string[],
): BelongsTo