Hierarchy

  • default

    Hierarchy

    • Model

Implements

  • default

Constructors

Properties

Accessors

Methods

[iterator] addRelation addWhereConstraint appendToEndpoint belongsTo belongsToMany call castAttribute clone compileQueryParameters createDescriptor delete deleteAttribute distinct except fill find findMany for forceFill freshTimestamps get getAttribute getAttributeKeys getAttributes getCastType getChanges getCreatedAtName getDeletedAtName getDeletedAttributes getEndpoint getFillable getFillableFromObject getGuarded getKey getKeyName getMorphs getName getNewAttributes getOriginal getRawAttributes getRawOriginal getRelation getRelationType getRelations getUpdatedAtName guessForeignKeyName has hasCast hasChanges hasGetAccessor hasMany hasOne hasSetMutator implementsCaster is isClean isDirty isFillable isGuarded isNot latest limit load loadedRelationKeys mergeCasts mergeFillable mergeGuarded morphMany morphOne morphTo new newInstanceFromResponseData offset oldest only orWhere orWhereBetween orWhereIn orWhereKey orWhereKeyNot orWhereNotBetween orWhereNotIn orWhereNotNull orWhereNull orderBy orderByDesc page patch post put refresh relationDefined relationLoaded removeRelation replicate reset resetEndpoint resetQueryParameters restore save scope select setAttribute setCasts setEndpoint setFillable setGuarded setLastSyncedAt setServerStringCase setStringCase skip syncOriginal throwIfModelDoesntExistsWhenCalling toJSON toString touch trashed unless update usesSoftDeletes usesTimestamps when where whereBetween whereIn whereKey whereKeyNot whereNotBetween whereNotIn whereNotNull whereNull with without all distinct factory find findMany get has latest limit make newQuery offset oldest orderBy orderByDesc page scope select skip unless when where whereBetween whereIn whereKey whereKeyNot whereNotBetween whereNotIn whereNotNull whereNull with without

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.

    Returns "camel" | "snake"

  • get exists(): boolean
  • Indicates whether the model exists on the backend or not.

    Returns boolean

  • get keyType(): "string" | "number"
  • Protected

    The type of the key that acts as the primary key of the model.

    Returns "string" | "number"

  • get loading(): boolean
  • Boolean flag indicating whether there is an ongoing request or not.

    Returns boolean

  • get relationMethodPrefix(): string
  • Protected

    The string all the relation methods expected to prefixed by.

    Returns

    Returns string

  • get serverAttributeCasing(): "camel" | "snake"
  • Protected

    Property indicating how attributes and relation names should be cast by default when sent to the server.

    Returns "camel" | "snake"

Methods

  • The iterator used for looping over the attributes and relations.

    Returns Iterator<any, any, undefined>

  • Protected

    Add a where constraint to the wheres.

    Returns

    Parameters

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

    Returns Model

  • Set the endpoint on the correct model for querying.

    Returns

    Type Parameters

    Type Parameters

    Parameters

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

    • Optional foreignKey: string

    Returns T

  • Set the endpoint on the correct model for querying.

    Returns

    Type Parameters

    Type Parameters

    Parameters

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

    • Optional relationName: string

      The name of the relation on the backend.

    Returns T

  • Protected

    The call method that mediates between the model and api handlers.

    Returns

    Type Parameters

    Type Parameters

    • T = any

    Parameters

    • method: "head" | "HEAD" | "GET" | "get"
    • 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

    Type Parameters

    • T = any

    Parameters

    Returns Promise<undefined | T>

  • Protected Internal

    Cast the attribute to the specified type.

    Returns

    Type Parameters

    Type Parameters

    • T

    Parameters

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

      The method to use when interacting with the AttributeCaster.

    Returns T

  • Protected

    Compiles the query parameters into a single object.

    Returns

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

  • Find the model based on the given id.

    Type Parameters

    Type Parameters

    Parameters

    • id: string | number

    Returns Promise<T>

  • Send a GET request to the endpoint.

    Returns

    Type Parameters

    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 | ModelCollection<T>>

  • Get an attribute from the model.

    Returns

    Type Parameters

    Type Parameters

    • K extends string

    • T extends unknown

    Parameters

    • key: K
    • defaultValue: T

    Returns T

  • Type Parameters

    Type Parameters

    • K extends string

    • T extends unknown

    Parameters

    • key: K
    • Optional defaultValue: T

    Returns undefined | T

  • Protected

    Get the type of cast for a model attribute.

    Returns

    Parameters

    • key: string

    Returns undefined | "object" | BuiltInCastType

  • Get the primary key for the model.

    Returns

    Type Parameters

    Type Parameters

    • T extends "string" | "number" = "string" | "number"

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

  • Get the polymorphic column names.

    Parameters

    • Optional name: string

    Returns Record<"type" | "id", string>

  • Protected

    Get the name of the relation type for the given relation.

    Returns

    Parameters

    • name: string

    Returns Relation

  • Guess the foreign key name that would be used to reference this model.

    Returns

    Returns string

  • Determine whether an attribute should be cast to a determined type.

    Returns

    Parameters

    • key: string

    Returns key is "object" | BuiltInCastType

  • Determine whether the given attribute has changed or attributes has been added or deleted.

    Returns

    Parameters

    • Optional key: string

    Returns boolean

  • Determine if a get accessor exists for an attribute.

    Returns

    Parameters

    • key: string

    Returns boolean

  • Set the endpoint on the correct model for querying.

    Returns

    Type Parameters

    Type Parameters

    Parameters

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

    • foreignKey: string = ...

    Returns T

  • Set the endpoint on the correct model for querying.

    Returns

    Type Parameters

    Type Parameters

    Parameters

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

    • foreignKey: string = ...

    Returns T

  • Determine if a set mutator exists for an attribute.

    Returns

    Parameters

    • key: string

    Returns boolean

  • Determine if two models have the same key and of the same type.

    Returns

    Type Parameters

    Type Parameters

    Parameters

    • model: unknown

    Returns model is M

  • Determine whether given or any attributes was changed.

    Parameters

    • Optional key: string

    Returns boolean

  • Alias for the hasChanges method.

    See

    hasChanges

    Returns

    Parameters

    • Optional key: string

    Returns boolean

  • Determine if the given attribute may not be mass assignable.

    Parameters

    • key: string

    Returns boolean

  • Determine if two models are not the same.

    See

    Model.prototype.is

    Returns

    Type Parameters

    Type Parameters

    Parameters

    • model: unknown

    Returns model is Exclude<unknown, M>

  • Load a relationships from remote.

    Returns

    Parameters

    • relations: MaybeArray<string>
    • forceReload: boolean = false

      Whether the already loaded relations should also be reloaded.

    Returns Promise<Model>

  • Set the endpoint on the correct model for querying.

    Returns

    Type Parameters

    Type Parameters

    Parameters

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

    • Optional morphName: string

    Returns T

  • Set the endpoint on the correct model for querying.

    Returns

    Type Parameters

    Type Parameters

    Parameters

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

    • Optional morphName: string

    Returns T

  • Add a constraint for the next query to return all relation.

    Returns

    Type Parameters

    Type Parameters

    Returns T

  • Get a subset of the model's attributes.

    Returns

    Type Parameters

    Type Parameters

    • K extends string[]

    • R = { [ P in string]?: unknown }

    Parameters

    • attributes: K

    Returns R

  • Type Parameters

    Type Parameters

    • K extends string

    • R = Record<K, Model[K]>

    Parameters

    • attributes: K

    Returns R

  • Add an or where between closure to the query.

    Returns

    Parameters

    • column: string
    • values: any[]

    Returns Model

  • Add an or where not between closure to the query.

    Returns

    Parameters

    • column: string
    • values: any[]

    Returns Model

  • Add an or where not in closure to the query.

    Returns

    Parameters

    • column: string
    • values: any[]

    Returns Model

  • Add an ordering of the records for the query.

    Returns

    Parameters

    • column: string
    • direction: Direction = 'asc'

    Returns Model

  • Protected

    Assert whether the relation has been defined on this instance.

    Returns

    Parameters

    • name: string

    Returns boolean

  • Determine if the given relation is loaded.

    Parameters

    • name: string

    Returns boolean

  • Set a given attribute on the model.

    Returns

    Type Parameters

    Type Parameters

    • K extends string

    • T extends unknown

    Parameters

    • key: K
    • value: T

    Returns Model

  • Type Parameters

    Type Parameters

    • K extends string

    • T

    Parameters

    • key: K
    • value: T

    Returns Model

  • Type Parameters

    Type Parameters

    • K extends string

    • T extends unknown = K extends string ? Model[K] : unknown

    Parameters

    • key: K
    • value: T

    Returns Model

  • Protected

    Set the last synced at attribute. This is only expected to be used when mocking model to look like it exists.

    Returns

    Parameters

    • to: unknown = ...

    Returns Model

  • Protected

    Utility to cast the given string to the serverAttributeCasing's case.

    See

    serverAttributeCasing

    Returns

    Parameters

    • key: string

    Returns string

  • Protected

    Utility to cast the given string to the attributeCasing's case.

    See

    attributeCasing

    Returns

    Parameters

    • key: string

    Returns string

  • Protected Internal

    Throw an error if the model does not exist before calling the specified method.

    Parameters

    • methodName: string

    Returns void

  • Call the provided function with the query if the given value is false.

    Returns

    Parameters

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

          Returns any

    Returns Model

  • Determine if the model uses soft deletes timestamp.

    Returns

    Returns boolean

  • Call the provided function with the query if the given value is true.

    Returns

    Parameters

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

          Returns any

    Returns Model

  • Add a where constraint to the query.

    Returns

    Parameters

    • column: string
    • Optional value: unknown

    Returns Model

  • Parameters

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

    Returns Model

  • Add a where between closure to the query.

    Parameters

    • column: string
    • values: any[]
    • boolean: BooleanOperator = 'and'

    Returns Model

  • Add a where in closure to the query.

    Parameters

    • column: string
    • values: any[]
    • boolean: BooleanOperator = 'and'

    Returns Model

  • Add a where not between closure to the query.

    Parameters

    • column: string
    • values: any[]
    • boolean: BooleanOperator = 'and'

    Returns Model

  • Add a where not in closure to the query.

    Parameters

    • column: string
    • values: any[]
    • boolean: BooleanOperator = 'and'

    Returns Model

  • The static version of the distinct method.

    Returns

    See

    BuildsQuery.prototype.distinct

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    Returns T["prototype"]

  • Call the factory fluently from the model.

    Type Parameters

    Type Parameters

    Parameters

    • this: T
    • times: number = 1

    Returns default<T["prototype"], Factory<T["prototype"]>>

  • The static version of the find method.

    See

    Model.prototype.find

    Type Parameters

    Type Parameters

    Parameters

    • this: T
    • id: string | number

    Returns Promise<T["prototype"]>

  • The get method made available as a static method.

    See

    CallsApi.prototype.get

    Type Parameters

    Type Parameters

    Parameters

    • this: T
    • 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"]>>

  • The static version of the has method.

    Returns

    See

    BuildsQuery.prototype.has

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    Returns T["prototype"]

  • The static version of the latest method.

    Returns

    See

    BuildsQuery.prototype.latest

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • Optional column: string

    Returns T["prototype"]

  • The static version of the limit method.

    See

    BuildsQuery.prototype.limit

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • count: number

    Returns T["prototype"]

  • Return the instantiated class.

    Returns

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T

    Returns T["prototype"]

  • The static version of the offset method.

    Returns

    See

    BuildsQuery.prototype.offset

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • count: number

    Returns T["prototype"]

  • The static version of the oldest method.

    Returns

    See

    BuildsQuery.prototype.oldest

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string = 'created_at'

    Returns T["prototype"]

  • The static version of the orderBy method.

    Returns

    See

    BuildsQuery.prototype.orderBy

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string
    • direction: Direction = 'asc'

    Returns T["prototype"]

  • The static version of the orderByDesc method.

    Returns

    See

    BuildsQuery.prototype.orderByDesc

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string

    Returns T["prototype"]

  • The static version of the page method.

    See

    BuildsQuery.prototype.page

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • pageNumber: number

    Returns T["prototype"]

  • The static version of the scope method.

    Returns

    See

    BuildsQuery.prototype.scope

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    Returns T["prototype"]

  • The static version of the select method.

    Returns

    See

    BuildsQuery.prototype.select

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    Returns T["prototype"]

  • The static version of the skip method.

    Returns

    See

    BuildsQuery.prototype.skip

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • count: number

    Returns T["prototype"]

  • The static version of the unless method.

    Returns

    See

    BuildsQuery.prototype.unless

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

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

          • instance: default

          Returns any

    Returns T["prototype"]

  • The static version of the when method.

    Returns

    See

    BuildsQuery.prototype.when

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

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

          • instance: default

          Returns any

    Returns T["prototype"]

  • The static version of the where method.

    Returns

    See

    BuildsQuery.prototype.where

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string
    • value: unknown

    Returns T["prototype"]

  • Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string
    • operator: Operator
    • value: unknown
    • Optional boolean: BooleanOperator

    Returns T["prototype"]

  • The static version of the whereBetween method.

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string
    • values: any[]
    • boolean: BooleanOperator = 'and'

    Returns T["prototype"]

  • The static version of the whereIn method.

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string
    • values: any[]
    • boolean: BooleanOperator = 'and'

    Returns T["prototype"]

  • The static version of the whereKey method.

    See

    BuildsQuery.prototype.whereKey

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • value: MaybeArray<string | number>
    • boolean: BooleanOperator = 'and'

    Returns T["prototype"]

  • The static version of the whereKeyNot method.

    See

    BuildsQuery.prototype.whereNotIn

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • value: MaybeArray<string | number>
    • boolean: BooleanOperator = 'and'

    Returns T["prototype"]

  • The static version of the whereNotBetween method.

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string
    • values: any[]
    • boolean: BooleanOperator = 'and'

    Returns T["prototype"]

  • The static version of the whereNotIn method.

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    • this: T
    • column: string
    • values: any[]
    • boolean: BooleanOperator = 'and'

    Returns T["prototype"]

  • The static version of the whereNotNull method.

    Returns

    See

    BuildsQuery.prototype.whereNotNull

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    Returns T["prototype"]

  • The static version of the whereNull method.

    Returns

    See

    BuildsQuery.prototype.whereNull

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    Returns T["prototype"]

  • The static version of the with method.

    Returns

    See

    BuildsQuery.prototype.with

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    Returns T["prototype"]

  • The static version of the with method.

    Returns

    See

    BuildsQuery.prototype.without

    Type Parameters

    Type Parameters

    • T extends StaticToThis

    Parameters

    Returns T["prototype"]

Generated using TypeDoc