Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • default
    • Model

Implements

  • default

Index

Constructors

Properties

Accessors

Methods

Constructors

Properties

attributeCasts: Record<string, CastType> = ...

The attributes that should be cast.

attributes: SimpleAttributes<default> = {}

The attributes.

columns: string[] = []

The requested columns for the query.

distinctBy: string[] = []

Return distinct rows by these columns.

fillableAttributes: string[] = ...

The attributes that are mass assignable.

guardedAttributes: string[] = ...

The attributes that aren't mass assignable

hasOneOrManyParentKeyName: undefined | string

The key name of the parent of this model which was instantiated from a hasOne or hasMany relation. This is used to remove the where query when saving a new entity like parent.$child().save({});

limitCount: number = 0

The limit of the number models requested on the query.

mutatedEndpoint: string = ''

The endpoint used when querying the api.

offsetCount: number = 0

The number of records to be skipped.

orders: Order[] = []

The column ordering for the query.

original: SimpleAttributes<default> = {}

The attribute's original state.

pageNumber: number = 0

The page number of the paginated models queried.

relations: Record<string, Model | ModelCollection<Model>> = {}

The loaded relations for the model. The keys do not include the relation prefixes.

relationsExists: string[] = []

The model relations to check for existence.

scopes: string[] = []

The backend scopes to be applied on the query.

softDeletes: boolean = true

Indicates if the model should expect a timestamp for soft-deletion.

timestamps: boolean = true

Indicates if the model should expect timestamps.

wheres: WhereDescription[] = []

The where constraints for the query.

withRelations: string[] = []

The relations that should be included on every request.

withouts: string[] = []

The override to remove the previously added relations from the request.

withs: string[] = []

The requested eager-loaded models for the query.

createdAt: string = 'created_at'

The name of the created at attribute on the server side.

deletedAt: string = 'deleted_at'

The name of the deleted at attribute on the server side.

updatedAt: string = 'updated_at'

The name of the updated at attribute on the server side.

Accessors

  • get attributeCasing(): "camel" | "snake"
  • Property indicating how attributes and relation names should be cast by default.

    readonly

    Returns "camel" | "snake"

  • get endpoint(): string
  • get exists(): boolean
  • get fillable(): string[]
  • get guarded(): string[]
  • get keyType(): "string" | "number"
  • The type of the key that acts as the primary key of the model.

    Returns "string" | "number"

  • get loading(): boolean
  • get primaryKey(): string
  • get relationMethodPrefix(): string
  • get serverAttributeCasing(): "camel" | "snake"
  • Property indicating how attributes and relation names should be cast by default when sent to the server.

    Returns "camel" | "snake"

Methods

  • [iterator](): Iterator<any, any, undefined>
  • addWhereConstraint(column: string, operator: Operator, value: any, boolean: BooleanOperator): Model
  • Add a where constraint to the wheres.

    Parameters

    • column: string
    • operator: Operator
    • value: any
    • boolean: BooleanOperator

    Returns Model

  • appendToEndpoint(string: string): Model
  • belongsTo<T>(related: new () => T, foreignKey?: string): T
  • Set the endpoint on the correct model for querying.

    Type parameters

    Parameters

    • related: new () => T
        • new (): T
        • Returns T

    • Optional foreignKey: string

    Returns T

  • belongsToMany<T>(related: new () => T, relationName?: string): T
  • Set the endpoint on the correct model for querying.

    Type parameters

    Parameters

    • related: new () => T
        • new (): T
        • Returns T

    • Optional relationName: string

      The name of the relation on the backend.

    Returns T

  • call<T>(method: "get" | "GET" | "HEAD" | "head", data?: SimpleAttributes<default> | Partial<{ columns: string[]; distinct: string[]; limit: number; offset: number; orders: Order[]; page: number; relationsExists: string[]; scopes: string[]; wheres: WhereDescription[]; with: string[] }>, customHeaders?: CustomHeaders): Promise<undefined | T>
  • call<T>(method: "delete" | "post" | "put" | "patch" | "DELETE" | "PATCH" | "POST" | "PUT", data?: SimpleAttributes<Model> | FormData | SimpleAttributes<default>, customHeaders?: CustomHeaders): Promise<undefined | T>
  • The call method that mediates between the model and api handlers.

    Type parameters

    • T = any

    Parameters

    • method: "get" | "GET" | "HEAD" | "head"
    • Optional data: SimpleAttributes<default> | Partial<{ columns: string[]; distinct: string[]; limit: number; offset: number; orders: Order[]; page: number; relationsExists: string[]; scopes: string[]; wheres: WhereDescription[]; with: string[] }>
    • Optional customHeaders: CustomHeaders

    Returns Promise<undefined | T>

  • Type parameters

    • T = any

    Parameters

    Returns Promise<undefined | T>

  • castAttribute<T>(key: string, value: any, method?: keyof AttributeCaster): T
  • Cast the attribute to the specified type.

    internal

    Type parameters

    • T

    Parameters

    • key: string
    • value: any
    • method: keyof AttributeCaster = 'get'

      The method to use when interacting with the AttributeCaster.

    Returns T

  • compileQueryParameters(): Partial<{ columns: string[]; distinct: string[]; limit: number; offset: number; orders: Order[]; page: number; relationsExists: string[]; scopes: string[]; wheres: WhereDescription[]; with: string[] }>
  • Compiles the query parameters into a single object.

    Returns Partial<{ columns: string[]; distinct: string[]; limit: number; offset: number; orders: Order[]; page: number; relationsExists: string[]; scopes: string[]; wheres: WhereDescription[]; with: string[] }>

  • deleteAttribute(key: string): Model
  • except<K, R>(attributes: K): R
  • except<K, R>(attributes: K): R
  • find<T>(id: string | number): Promise<T>
  • freshTimestamps(): Promise<Model>
  • get<T>(queryParameters?: Partial<{ columns: string[]; distinct: string[]; limit: number; offset: number; orders: Order[]; page: number; relationsExists: string[]; scopes: string[]; wheres: WhereDescription[]; with: string[] }> & Record<string, unknown>): Promise<T | ModelCollection<T>>
  • Send a GET request to the endpoint.

    Type parameters

    Parameters

    • Optional queryParameters: Partial<{ columns: string[]; distinct: string[]; limit: number; offset: number; orders: Order[]; page: number; relationsExists: string[]; scopes: string[]; wheres: WhereDescription[]; with: string[] }> & Record<string, unknown>

    Returns Promise<T | ModelCollection<T>>

  • getAttribute<K, T>(key: K, defaultValue: T): T
  • getAttribute<K, T>(key: K, defaultValue?: T): undefined | T
  • getAttributeKeys(): string[]
  • getCastType(key: string): undefined | "object" | BuiltInCastType
  • getCreatedAtName(): string
  • getDeletedAtName(): string
  • getDeletedAttributes<K>(key: K): Record<K, undefined | Model[K]>
  • getDeletedAttributes(key?: string): Partial<SimpleAttributes<Model>>
  • getEndpoint(): string
  • getFillable(): string[]
  • getGuarded(): string[]
  • getKey<T>(): undefined | (T extends "number" ? number : string)
  • Get the primary key for the model.

    Type parameters

    • T: "string" | "number" = "string" | "number"

    Returns undefined | (T extends "number" ? number : string)

  • getKeyName(): string
  • getMorphs(name?: string): Record<"id" | "type", string>
  • getName(): string
  • getRelationType(name: string): Relation
  • getUpdatedAtName(): string
  • guessForeignKeyName(): string
  • hasCast(key: string): key is "object" | BuiltInCastType
  • Determine whether an attribute should be cast to a determined type.

    Parameters

    • key: string

    Returns key is "object" | BuiltInCastType

  • hasChanges(key?: string): boolean
  • Determine whether the given attribute has changed or attributes has been added or deleted.

    Parameters

    • Optional key: string

    Returns boolean

  • hasGetAccessor(key: string): boolean
  • hasMany<T>(related: new () => T, foreignKey?: string): T
  • Set the endpoint on the correct model for querying.

    Type parameters

    Parameters

    • related: new () => T
        • new (): T
        • Returns T

    • foreignKey: string = ...

    Returns T

  • hasOne<T>(related: new () => T, foreignKey?: string): T
  • Set the endpoint on the correct model for querying.

    Type parameters

    Parameters

    • related: new () => T
        • new (): T
        • Returns T

    • foreignKey: string = ...

    Returns T

  • hasSetMutator(key: string): boolean
  • is<M>(model: unknown): model is M
  • Determine if two models have the same key and of the same type.

    Type parameters

    Parameters

    • model: unknown

    Returns model is M

  • isClean(key?: string): boolean
  • isDirty(key?: string): boolean
  • isFillable(key: string): boolean
  • isGuarded(key: string): boolean
  • isNot<M>(model: unknown): model is Exclude<unknown, M>
  • Determine if two models are not the same.

    see

    Model.prototype.is

    Type parameters

    Parameters

    • model: unknown

    Returns model is Exclude<unknown, M>

  • latest(column?: string): Model
  • limit(count: number): Model
  • loadedRelationKeys(): string[]
  • mergeFillable(fillable: string[]): Model
  • mergeGuarded(guarded: string[]): Model
  • morphMany<T>(related: new () => T, morphName?: string): T
  • Set the endpoint on the correct model for querying.

    Type parameters

    Parameters

    • related: new () => T
        • new (): T
        • Returns T

    • Optional morphName: string

    Returns T

  • morphOne<T>(related: new () => T, morphName?: string): T
  • Set the endpoint on the correct model for querying.

    Type parameters

    Parameters

    • related: new () => T
        • new (): T
        • Returns T

    • Optional morphName: string

    Returns T

  • morphTo<T>(): T
  • offset(count: number): Model
  • oldest(column?: string): Model
  • only<K, R>(attributes: K): R
  • only<K, R>(attributes: K): R
  • orWhere(column: string, operator: any, value?: any): Model
  • orWhereBetween(column: string, values: any[]): Model
  • orWhereIn(column: string, values: any[]): Model
  • orWhereNotBetween(column: string, values: any[]): Model
  • orWhereNotIn(column: string, values: any[]): Model
  • orderBy(column: string, direction?: Direction): Model
  • orderByDesc(column: string): Model
  • page(pageNumber: number): Model
  • refresh(): Promise<Model>
  • relationDefined(name: string): boolean
  • relationLoaded(name: string): boolean
  • removeRelation(name: string): Model
  • resetQueryParameters(): Model
  • restore(): Promise<Model>
  • setAttribute<K, T>(key: K, value: T): Model
  • setAttribute<K, T>(key: K, value: T): Model
  • setAttribute<K, T>(key: K, value: T): Model
  • setEndpoint(url: string): Model
  • setFillable(fillable: string[]): Model
  • setGuarded(guarded: string[]): Model
  • setLastSyncedAt(to?: unknown): Model
  • setServerStringCase(key: string): string
  • Utility to cast the given string to the serverAttributeCasing's case.

    see

    serverAttributeCasing

    Parameters

    • key: string

    Returns string

  • setStringCase(key: string): string
  • Utility to cast the given string to the attributeCasing's case.

    see

    attributeCasing

    Parameters

    • key: string

    Returns string

  • skip(count: number): Model
  • throwIfModelDoesntExistsWhenCalling(methodName: string): void
  • Throw an error if the model does not exists before calling the specified method.

    internal

    Parameters

    • methodName: string

    Returns void

  • toJSON<T>(): T
  • toString(): string
  • Utility to recursively format the keys according to the server argument.

    Parameters

    • attributes: Attributes<default>

      The object which should

    • server: boolean

      whether to use the serverAttributeCasing or attributeCasing

    Returns Attributes<default>

  • trashed(): boolean
  • unless(value: any, closure: (instance: Model) => any): Model
  • usesSoftDeletes(): boolean
  • usesTimestamps(): boolean
  • when(value: any, closure: (instance: Model) => any): Model
  • where(column: string, operator: unknown, value?: unknown, boolean?: BooleanOperator): Model
  • Add a where constraint to the query.

    Parameters

    • column: string
    • operator: unknown
    • Optional value: unknown
    • boolean: BooleanOperator = 'and'

    Returns Model

  • whereBetween(column: string, values: any[], boolean?: BooleanOperator): Model
  • whereIn(column: string, values: any[], boolean?: BooleanOperator): Model
  • whereKey(value: MaybeArray<string | number>, boolean?: BooleanOperator): Model
  • whereKeyNot(value: MaybeArray<string | number>, boolean?: BooleanOperator): Model
  • whereNotBetween(column: string, values: any[], boolean?: BooleanOperator): Model
  • whereNotIn(column: string, values: any[], boolean?: BooleanOperator): Model
  • whereNotNull(columns: MaybeArray<string>, boolean?: BooleanOperator): Model
  • distinct<T>(columns: MaybeArray<string>): T["prototype"]
  • The static version of the distinct method.

    see

    BuildsQuery.prototype.distinct

    Type parameters

    • T: StaticToThis

    Parameters

    Returns T["prototype"]

  • factory<T>(times: number): default<T["prototype"], Factory<T["prototype"]>>
  • find<T>(id: string | number): Promise<T["prototype"]>
  • findMany<T>(ids: (string | number)[]): Promise<ModelCollection<T["prototype"]>>
  • get<T>(queryParameters?: Partial<{ columns: string[]; distinct: string[]; limit: number; offset: number; orders: Order[]; page: number; relationsExists: string[]; scopes: string[]; wheres: WhereDescription[]; with: string[] }> & Record<string, unknown>): Promise<T["prototype"] | ModelCollection<T["prototype"]>>
  • The get method made available as a static method.

    see

    CallsApi.prototype.get

    Type parameters

    Parameters

    • Optional queryParameters: Partial<{ columns: string[]; distinct: string[]; limit: number; offset: number; orders: Order[]; page: number; relationsExists: string[]; scopes: string[]; wheres: WhereDescription[]; with: string[] }> & Record<string, unknown>

      append and/or overwrite query parameter values.

    Returns Promise<T["prototype"] | ModelCollection<T["prototype"]>>

  • has<T>(relations: MaybeArray<string>): T["prototype"]
  • latest<T>(column?: string): T["prototype"]
  • The static version of the latest method.

    see

    BuildsQuery.prototype.latest

    Type parameters

    • T: StaticToThis

    Parameters

    • Optional column: string

    Returns T["prototype"]

  • limit<T>(count: number): T["prototype"]
  • The static version of the limit method.

    see

    BuildsQuery.prototype.limit

    Type parameters

    • T: StaticToThis

    Parameters

    • count: number

    Returns T["prototype"]

  • newQuery<T>(): T["prototype"]
  • offset<T>(count: number): T["prototype"]
  • The static version of the offset method.

    see

    BuildsQuery.prototype.offset

    Type parameters

    • T: StaticToThis

    Parameters

    • count: number

    Returns T["prototype"]

  • oldest<T>(column: string): T["prototype"]
  • The static version of the oldest method.

    see

    BuildsQuery.prototype.oldest

    Type parameters

    • T: StaticToThis

    Parameters

    • column: string

    Returns T["prototype"]

  • orderBy<T>(column: string, direction: Direction): T["prototype"]
  • The static version of the orderBy method.

    see

    BuildsQuery.prototype.orderBy

    Type parameters

    • T: StaticToThis

    Parameters

    • column: string
    • direction: Direction

    Returns T["prototype"]

  • orderByDesc<T>(column: string): T["prototype"]
  • The static version of the orderByDesc method.

    see

    BuildsQuery.prototype.orderByDesc

    Type parameters

    • T: StaticToThis

    Parameters

    • column: string

    Returns T["prototype"]

  • page<T>(pageNumber: number): T["prototype"]
  • The static version of the page method.

    see

    BuildsQuery.prototype.page

    Type parameters

    • T: StaticToThis

    Parameters

    • pageNumber: number

    Returns T["prototype"]

  • scope<T>(scopes: MaybeArray<string>): T["prototype"]
  • select<T>(columns: MaybeArray<string>): T["prototype"]
  • skip<T>(count: number): T["prototype"]
  • The static version of the skip method.

    see

    BuildsQuery.prototype.skip

    Type parameters

    • T: StaticToThis

    Parameters

    • count: number

    Returns T["prototype"]

  • unless<T>(value: any, closure: (instance: default) => any): T["prototype"]
  • The static version of the unless method.

    see

    BuildsQuery.prototype.unless

    Type parameters

    • T: StaticToThis

    Parameters

    • value: any
    • closure: (instance: default) => any
        • (instance: default): any
        • Parameters

          • instance: default

          Returns any

    Returns T["prototype"]

  • when<T>(value: any, closure: (instance: default) => any): T["prototype"]
  • The static version of the when method.

    see

    BuildsQuery.prototype.when

    Type parameters

    • T: StaticToThis

    Parameters

    • value: any
    • closure: (instance: default) => any
        • (instance: default): any
        • Parameters

          • instance: default

          Returns any

    Returns T["prototype"]

  • where<T>(column: string, operator: unknown, value?: unknown, boolean: BooleanOperator): T["prototype"]
  • The static version of the where method.

    see

    BuildsQuery.prototype.where

    Type parameters

    • T: StaticToThis

    Parameters

    • column: string
    • operator: unknown
    • Optional value: unknown
    • boolean: BooleanOperator

    Returns T["prototype"]

  • whereBetween<T>(column: string, values: any[], boolean: BooleanOperator): T["prototype"]
  • The static version of the whereBetween method.

    see

    BuildsQuery.prototype.whereBetween

    Type parameters

    • T: StaticToThis

    Parameters

    • column: string
    • values: any[]
    • boolean: BooleanOperator

    Returns T["prototype"]

  • whereIn<T>(column: string, values: any[], boolean: BooleanOperator): T["prototype"]
  • The static version of the whereIn method.

    see

    BuildsQuery.prototype.whereIn

    Type parameters

    • T: StaticToThis

    Parameters

    • column: string
    • values: any[]
    • boolean: BooleanOperator

    Returns T["prototype"]

  • whereKey<T>(value: MaybeArray<string | number>, boolean: BooleanOperator): T["prototype"]
  • The static version of the whereKey method.

    see

    BuildsQuery.prototype.whereKey

    Type parameters

    • T: StaticToThis

    Parameters

    • value: MaybeArray<string | number>
    • boolean: BooleanOperator

    Returns T["prototype"]

  • whereKeyNot<T>(value: MaybeArray<string | number>, boolean: BooleanOperator): T["prototype"]
  • The static version of the whereKeyNot method.

    see

    BuildsQuery.prototype.whereNotIn

    Type parameters

    • T: StaticToThis

    Parameters

    • value: MaybeArray<string | number>
    • boolean: BooleanOperator

    Returns T["prototype"]

  • whereNotBetween<T>(column: string, values: any[], boolean: BooleanOperator): T["prototype"]
  • The static version of the whereNotBetween method.

    see

    BuildsQuery.prototype.whereNotBetween

    Type parameters

    • T: StaticToThis

    Parameters

    • column: string
    • values: any[]
    • boolean: BooleanOperator

    Returns T["prototype"]

  • whereNotIn<T>(column: string, values: any[], boolean: BooleanOperator): T["prototype"]
  • The static version of the whereNotIn method.

    see

    BuildsQuery.prototype.whereNotIn

    Type parameters

    • T: StaticToThis

    Parameters

    • column: string
    • values: any[]
    • boolean: BooleanOperator

    Returns T["prototype"]

  • whereNotNull<T>(columns: MaybeArray<string>): T["prototype"]
  • The static version of the whereNotNull method.

    see

    BuildsQuery.prototype.whereNotNull

    Type parameters

    • T: StaticToThis

    Parameters

    Returns T["prototype"]

  • whereNull<T>(columns: MaybeArray<string>): T["prototype"]
  • The static version of the whereNull method.

    see

    BuildsQuery.prototype.whereNull

    Type parameters

    • T: StaticToThis

    Parameters

    Returns T["prototype"]

  • with<T>(relations: MaybeArray<string>): T["prototype"]
  • without<T>(relations: MaybeArray<string>): T["prototype"]
  • The static version of the with method.

    see

    BuildsQuery.prototype.without

    Type parameters

    • T: StaticToThis

    Parameters

    Returns T["prototype"]

Generated using TypeDoc