belongsTo()

Makes a "belong to" relation of the property


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, Attr, Str, BelongsTo } from 'pinia-orm'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,  ownerKey?: string,): BelongsTo