hasMany

Usage

import { Model } from 'pinia-orm'
import Comment from './Comment'
class Post extends Model {
  static entity = 'posts'
  static fields () {
    return {
      id: this.attr(null),
      title: this.string(''),
      comments: this.hasMany(Comment, 'postId')
    }
  }
}

With Decorator

import { Model } from 'pinia-orm'
import { Attr, HasMany, Str } from 'pinia-orm/decorators'
import Comment from './Comment'
class Post extends Model {
  static entity = 'posts'
  
  @Attr(null) declare id: number | null
  @Str('') declare title: string
  @HasMany(() => Comment, 'postId') declare comments: Comment[]
}

Typescript Declarations

function hasMany(
  related: typeof Model,
  foreignKey: string | string[],
  localKey?: string | string[],
): HasMany