@bunyad/orm 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/casts.d.ts +50 -0
- package/dist/casts.js +309 -0
- package/dist/concerns.d.ts +64 -0
- package/dist/concerns.js +216 -0
- package/dist/decorators.d.ts +7 -0
- package/dist/decorators.js +12 -0
- package/dist/eager-fetch.d.ts +7 -0
- package/dist/eager-fetch.js +38 -0
- package/dist/eager.d.ts +24 -0
- package/dist/eager.js +854 -0
- package/dist/factory.d.ts +68 -0
- package/dist/factory.js +265 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9 -0
- package/dist/model-events.d.ts +43 -0
- package/dist/model-events.js +138 -0
- package/dist/model-helpers.d.ts +32 -0
- package/dist/model-helpers.js +99 -0
- package/dist/model-query.d.ts +312 -0
- package/dist/model-query.js +3170 -0
- package/dist/model-strictness.d.ts +35 -0
- package/dist/model-strictness.js +114 -0
- package/dist/model.d.ts +490 -0
- package/dist/model.js +1931 -0
- package/dist/orm-collection.d.ts +37 -0
- package/dist/orm-collection.js +150 -0
- package/dist/pivot.d.ts +9 -0
- package/dist/pivot.js +9 -0
- package/dist/relations.d.ts +335 -0
- package/dist/relations.js +1164 -0
- package/dist/scopes.d.ts +36 -0
- package/dist/scopes.js +128 -0
- package/package.json +49 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Laravel Eloquent strictness + touching guards.
|
|
3
|
+
* @see Illuminate\Database\Eloquent\Model::preventLazyLoading
|
|
4
|
+
* @see Model::preventSilentlyDiscardingAttributes
|
|
5
|
+
* @see Model::preventAccessingMissingAttributes
|
|
6
|
+
* @see Model::shouldBeStrict
|
|
7
|
+
* @see Model::withoutTouching
|
|
8
|
+
*/
|
|
9
|
+
export declare function enterEagerLoad(): void;
|
|
10
|
+
export declare function leaveEagerLoad(): void;
|
|
11
|
+
export declare function isInsideEagerLoad(): boolean;
|
|
12
|
+
export declare class LazyLoadingViolationException extends Error {
|
|
13
|
+
constructor(model: string, relation: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class MassAssignmentException extends Error {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class MissingAttributeException extends Error {
|
|
19
|
+
constructor(model: string, key: string);
|
|
20
|
+
}
|
|
21
|
+
export declare function modelsShouldPreventLazyLoading(): boolean;
|
|
22
|
+
export declare function modelsShouldPreventSilentlyDiscardingAttributes(): boolean;
|
|
23
|
+
export declare function modelsShouldPreventAccessingMissingAttributes(): boolean;
|
|
24
|
+
export declare function preventLazyLoading(prevent?: boolean): void;
|
|
25
|
+
export declare function preventSilentlyDiscardingAttributes(prevent?: boolean): void;
|
|
26
|
+
export declare function preventAccessingMissingAttributes(prevent?: boolean): void;
|
|
27
|
+
export declare function shouldBeStrict(should?: boolean): void;
|
|
28
|
+
/** Test helper — reset all strictness / touch flags. */
|
|
29
|
+
export declare function resetModelStrictnessForTests(): void;
|
|
30
|
+
export declare function isIgnoringTouch(modelClass?: object): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Run without touching parent timestamps (Laravel `Model::withoutTouching`).
|
|
33
|
+
* Pass model classes to limit the ignore set; omit to ignore all models.
|
|
34
|
+
*/
|
|
35
|
+
export declare function withoutTouching<T>(modelsOrCallback: object[] | (() => T | Promise<T>), callback?: () => T | Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Laravel Eloquent strictness + touching guards.
|
|
3
|
+
* @see Illuminate\Database\Eloquent\Model::preventLazyLoading
|
|
4
|
+
* @see Model::preventSilentlyDiscardingAttributes
|
|
5
|
+
* @see Model::preventAccessingMissingAttributes
|
|
6
|
+
* @see Model::shouldBeStrict
|
|
7
|
+
* @see Model::withoutTouching
|
|
8
|
+
*/
|
|
9
|
+
/** Depth of active eager-load work — `related()` must not trip lazy-load prevention. */
|
|
10
|
+
let eagerLoadDepth = 0;
|
|
11
|
+
export function enterEagerLoad() {
|
|
12
|
+
eagerLoadDepth += 1;
|
|
13
|
+
}
|
|
14
|
+
export function leaveEagerLoad() {
|
|
15
|
+
eagerLoadDepth = Math.max(0, eagerLoadDepth - 1);
|
|
16
|
+
}
|
|
17
|
+
export function isInsideEagerLoad() {
|
|
18
|
+
return eagerLoadDepth > 0;
|
|
19
|
+
}
|
|
20
|
+
let preventsLazyLoading = false;
|
|
21
|
+
let preventsSilentlyDiscardingAttributes = false;
|
|
22
|
+
let preventsAccessingMissingAttributes = false;
|
|
23
|
+
/** Classes currently ignoring touch (empty set = ignore all when flag set). */
|
|
24
|
+
let ignoringTouch = false;
|
|
25
|
+
let ignoringTouchModels = null;
|
|
26
|
+
export class LazyLoadingViolationException extends Error {
|
|
27
|
+
constructor(model, relation) {
|
|
28
|
+
super(`Attempted to lazy load [${relation}] on model [${model}] but lazy loading is disabled.`);
|
|
29
|
+
this.name = "LazyLoadingViolationException";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class MassAssignmentException extends Error {
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = "MassAssignmentException";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class MissingAttributeException extends Error {
|
|
39
|
+
constructor(model, key) {
|
|
40
|
+
super(`The attribute [${key}] either does not exist or was not retrieved for model [${model}].`);
|
|
41
|
+
this.name = "MissingAttributeException";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function modelsShouldPreventLazyLoading() {
|
|
45
|
+
return preventsLazyLoading;
|
|
46
|
+
}
|
|
47
|
+
export function modelsShouldPreventSilentlyDiscardingAttributes() {
|
|
48
|
+
return preventsSilentlyDiscardingAttributes;
|
|
49
|
+
}
|
|
50
|
+
export function modelsShouldPreventAccessingMissingAttributes() {
|
|
51
|
+
return preventsAccessingMissingAttributes;
|
|
52
|
+
}
|
|
53
|
+
export function preventLazyLoading(prevent = true) {
|
|
54
|
+
preventsLazyLoading = prevent;
|
|
55
|
+
}
|
|
56
|
+
export function preventSilentlyDiscardingAttributes(prevent = true) {
|
|
57
|
+
preventsSilentlyDiscardingAttributes = prevent;
|
|
58
|
+
}
|
|
59
|
+
export function preventAccessingMissingAttributes(prevent = true) {
|
|
60
|
+
preventsAccessingMissingAttributes = prevent;
|
|
61
|
+
}
|
|
62
|
+
export function shouldBeStrict(should = true) {
|
|
63
|
+
preventLazyLoading(should);
|
|
64
|
+
preventSilentlyDiscardingAttributes(should);
|
|
65
|
+
preventAccessingMissingAttributes(should);
|
|
66
|
+
}
|
|
67
|
+
/** Test helper — reset all strictness / touch flags. */
|
|
68
|
+
export function resetModelStrictnessForTests() {
|
|
69
|
+
preventsLazyLoading = false;
|
|
70
|
+
preventsSilentlyDiscardingAttributes = false;
|
|
71
|
+
preventsAccessingMissingAttributes = false;
|
|
72
|
+
eagerLoadDepth = 0;
|
|
73
|
+
ignoringTouch = false;
|
|
74
|
+
ignoringTouchModels = null;
|
|
75
|
+
}
|
|
76
|
+
export function isIgnoringTouch(modelClass) {
|
|
77
|
+
if (!ignoringTouch)
|
|
78
|
+
return false;
|
|
79
|
+
if (!ignoringTouchModels || ignoringTouchModels.size === 0)
|
|
80
|
+
return true;
|
|
81
|
+
if (!modelClass)
|
|
82
|
+
return true;
|
|
83
|
+
return ignoringTouchModels.has(modelClass);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Run without touching parent timestamps (Laravel `Model::withoutTouching`).
|
|
87
|
+
* Pass model classes to limit the ignore set; omit to ignore all models.
|
|
88
|
+
*/
|
|
89
|
+
export async function withoutTouching(modelsOrCallback, callback) {
|
|
90
|
+
let models = null;
|
|
91
|
+
let cb;
|
|
92
|
+
if (typeof modelsOrCallback === "function") {
|
|
93
|
+
cb = modelsOrCallback;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
models = modelsOrCallback;
|
|
97
|
+
if (!callback) {
|
|
98
|
+
throw new Error("withoutTouching requires a callback.");
|
|
99
|
+
}
|
|
100
|
+
cb = callback;
|
|
101
|
+
}
|
|
102
|
+
const prevIgnoring = ignoringTouch;
|
|
103
|
+
const prevModels = ignoringTouchModels;
|
|
104
|
+
ignoringTouch = true;
|
|
105
|
+
ignoringTouchModels =
|
|
106
|
+
models && models.length > 0 ? new Set(models) : null;
|
|
107
|
+
try {
|
|
108
|
+
return await cb();
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
ignoringTouch = prevIgnoring;
|
|
112
|
+
ignoringTouchModels = prevModels;
|
|
113
|
+
}
|
|
114
|
+
}
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import type { Connection, DatabaseManager, DateInput } from "@bunyad/database";
|
|
2
|
+
import { LengthAwarePaginator, CursorPaginator } from "@bunyad/database";
|
|
3
|
+
import { Collection } from "@bunyad/common";
|
|
4
|
+
import { OrmCollection } from "./orm-collection.js";
|
|
5
|
+
import { type CastDefinition } from "./casts.js";
|
|
6
|
+
import { type ModelEventListener, type ModelEventName, type ModelObserver } from "./model-events.js";
|
|
7
|
+
import { type GlobalScopeCallback } from "./scopes.js";
|
|
8
|
+
import { BelongsTo, BelongsToMany, HasMany, HasManyThrough, HasOne, HasOneThrough, MorphMany, MorphOne, MorphTo, MorphToMany, type MorphToManyOptions } from "./relations.js";
|
|
9
|
+
import { ModelQuery } from "./model-query.js";
|
|
10
|
+
export type { CastType, CastDefinition, EnumCast } from "./casts.js";
|
|
11
|
+
export { Attribute, AsCollection, AsFluent, AsEnumCollection, } from "./casts.js";
|
|
12
|
+
export type { ModelEventName, ModelEventListener, ModelObserver, } from "./model-events.js";
|
|
13
|
+
export { resetModelEventsForTests } from "./model-events.js";
|
|
14
|
+
/** Thrown when a model query returns no results. */
|
|
15
|
+
export declare class ModelNotFoundException extends Error {
|
|
16
|
+
constructor(message?: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Relation factory on `static relations`.
|
|
20
|
+
* Parameter is bivariant so subclasses may type `(m: Contact) => …`
|
|
21
|
+
* without breaking `typeof Contact` assignability to `typeof Model`.
|
|
22
|
+
*/
|
|
23
|
+
export type RelationFactory = {
|
|
24
|
+
bivarianceHack(model: Model): unknown;
|
|
25
|
+
}["bivarianceHack"];
|
|
26
|
+
export type RelationsMap = Record<string, RelationFactory> | (() => Record<string, RelationFactory>);
|
|
27
|
+
export type ModelClass = typeof Model & {
|
|
28
|
+
table: string;
|
|
29
|
+
primaryKey: string;
|
|
30
|
+
softDeletes?: boolean;
|
|
31
|
+
deletedAt?: string;
|
|
32
|
+
/** Property or method (`casts()`). */
|
|
33
|
+
casts?: Record<string, CastDefinition> | (() => Record<string, CastDefinition>);
|
|
34
|
+
/** Relation factories (`static relations = { posts: (m) => m.hasMany(Post) }`). */
|
|
35
|
+
relations?: RelationsMap;
|
|
36
|
+
hidden?: string[];
|
|
37
|
+
appends?: string[];
|
|
38
|
+
fillable?: readonly string[] | string[];
|
|
39
|
+
guarded?: readonly string[] | string[];
|
|
40
|
+
};
|
|
41
|
+
export type ModelQueryOptions = {
|
|
42
|
+
withTrashed?: boolean;
|
|
43
|
+
onlyTrashed?: boolean;
|
|
44
|
+
eagerLoad?: import("./model-helpers.js").NormalizedEagerRelation[];
|
|
45
|
+
withoutGlobalScopes?: true | string[];
|
|
46
|
+
/** Named connection (`User.on('secondary')`) or a Connection handle. */
|
|
47
|
+
connection?: string | Connection;
|
|
48
|
+
/**
|
|
49
|
+
* Nested `where(callback)` group — BelongsTo whereHas must use IN/EXISTS,
|
|
50
|
+
* not JOIN (nested builders only emit WHERE SQL).
|
|
51
|
+
*/
|
|
52
|
+
nestedWhereGroup?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/** Resolve a connection name or handle to a live Connection. */
|
|
55
|
+
export declare function resolveConnection(connection?: string | Connection | null): Connection;
|
|
56
|
+
export declare function filterFillable(model: ModelClass, attributes: Record<string, unknown>): Record<string, unknown>;
|
|
57
|
+
/** True when hydrating this row must run cast getters (partial selects often do not). */
|
|
58
|
+
export declare function attributesNeedModelCasts(ctor: ModelClass, attributes: Record<string, unknown>): boolean;
|
|
59
|
+
export declare function canFastFind(ctor: ModelClass): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Active Record model — familiar query/relation APIs for app code.
|
|
62
|
+
*/
|
|
63
|
+
export declare class Model {
|
|
64
|
+
#private;
|
|
65
|
+
static table: string;
|
|
66
|
+
static primaryKey: string;
|
|
67
|
+
/**
|
|
68
|
+
* `$incrementing` — false for UUID / ULID / assigned keys.
|
|
69
|
+
* When false, `save()` inserts the primary key instead of `insertGetId`.
|
|
70
|
+
*/
|
|
71
|
+
static incrementing: boolean;
|
|
72
|
+
/** `$keyType` (`int` | `string`). */
|
|
73
|
+
static keyType: "int" | "string";
|
|
74
|
+
/** Connection name (`"secondary"`) or Connection handle. */
|
|
75
|
+
static connection?: string | Connection;
|
|
76
|
+
/** SoftDeletes stand-in (`@SoftDeletes()` sets this). */
|
|
77
|
+
static softDeletes: boolean;
|
|
78
|
+
static deletedAt: string;
|
|
79
|
+
/** Set by `@HasFactory(...)` — call `Model.factory().create()`. */
|
|
80
|
+
static factory?: () => import("./factory.js").Factory<any>;
|
|
81
|
+
/** When false, `save()` skips `created_at` / `updated_at`. */
|
|
82
|
+
static timestamps: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Laravel `$casts` property — prefer `static casts()` when adding enums / Attribute.
|
|
85
|
+
* May be a plain object or a method returning the map.
|
|
86
|
+
*/
|
|
87
|
+
static casts: Record<string, CastDefinition> | (() => Record<string, CastDefinition>);
|
|
88
|
+
/**
|
|
89
|
+
* Relation definitions. Prefer this over instance methods so you can
|
|
90
|
+
* `declare product: Product | null` and use `model.product` after eager load,
|
|
91
|
+
* with `model.related('product')` for the relation query.
|
|
92
|
+
*/
|
|
93
|
+
static relations: RelationsMap;
|
|
94
|
+
/**
|
|
95
|
+
* Laravel `$touches` — relation names whose related models get `touch()` after
|
|
96
|
+
* this model is saved (or soft-deleted). Honor `withoutTouching`.
|
|
97
|
+
*/
|
|
98
|
+
static touches: string[];
|
|
99
|
+
/** Laravel `$hidden`. */
|
|
100
|
+
static hidden: string[];
|
|
101
|
+
/** Laravel `$visible` allow-list (empty = all non-hidden). */
|
|
102
|
+
static visible: string[];
|
|
103
|
+
/** Laravel `$appends` — accessors included in `toArray()`. */
|
|
104
|
+
static appends: string[];
|
|
105
|
+
/** Laravel `$fillable`. */
|
|
106
|
+
static fillable: readonly string[] | string[];
|
|
107
|
+
/** Laravel `$guarded` — default guard all until fillable is set. */
|
|
108
|
+
static guarded: readonly string[] | string[];
|
|
109
|
+
id: string | number;
|
|
110
|
+
/** Laravel `$exists` — true after retrieve / successful insert. */
|
|
111
|
+
get exists(): boolean;
|
|
112
|
+
set exists(value: boolean);
|
|
113
|
+
constructor(attributes?: Record<string, unknown>);
|
|
114
|
+
/**
|
|
115
|
+
* `newFromBuilder` — hydrate a persisted row (sets `$exists`).
|
|
116
|
+
* Used by ModelQuery list/find paths.
|
|
117
|
+
*/
|
|
118
|
+
static newFromBuilder<T extends typeof Model>(this: T, attributes: Record<string, unknown>): InstanceType<T>;
|
|
119
|
+
/** Snapshot current attributes as the original set. */
|
|
120
|
+
syncOriginal(): this;
|
|
121
|
+
/** Current attribute bag (non-function own properties). */
|
|
122
|
+
getAttributes(): Record<string, unknown>;
|
|
123
|
+
/**
|
|
124
|
+
* Laravel `getAttribute` — throws when `preventAccessingMissingAttributes` is on
|
|
125
|
+
* and the key was not retrieved / does not exist (relations exempt).
|
|
126
|
+
*/
|
|
127
|
+
getAttribute(key: string): unknown;
|
|
128
|
+
/** Laravel `isDirty`. */
|
|
129
|
+
isDirty(...attributes: string[]): boolean;
|
|
130
|
+
/** Laravel `isClean`. */
|
|
131
|
+
isClean(...attributes: string[]): boolean;
|
|
132
|
+
/** Laravel `getDirty`. */
|
|
133
|
+
getDirty(): Record<string, unknown>;
|
|
134
|
+
/** Laravel `getOriginal`. */
|
|
135
|
+
getOriginal(): Record<string, unknown>;
|
|
136
|
+
getOriginal(key: string): unknown;
|
|
137
|
+
/** Laravel `getChanges` — attributes changed by the last save. */
|
|
138
|
+
getChanges(): Record<string, unknown>;
|
|
139
|
+
/** Laravel `wasChanged`. */
|
|
140
|
+
wasChanged(...attributes: string[]): boolean;
|
|
141
|
+
/** Laravel `wasRecentlyCreated`. */
|
|
142
|
+
wasRecentlyCreated(): boolean;
|
|
143
|
+
/** Laravel `append`. */
|
|
144
|
+
append(...attributes: string[]): this;
|
|
145
|
+
/** Laravel `setAppends`. */
|
|
146
|
+
setAppends(attributes: string[]): this;
|
|
147
|
+
/** Laravel `getAppends`. */
|
|
148
|
+
getAppends(): string[];
|
|
149
|
+
/** Laravel `getHidden`. */
|
|
150
|
+
getHidden(): string[];
|
|
151
|
+
/** Laravel `getVisible`. */
|
|
152
|
+
getVisible(): string[];
|
|
153
|
+
/** Laravel `setHidden`. */
|
|
154
|
+
setHidden(attributes: string[]): this;
|
|
155
|
+
/** Laravel `setVisible`. */
|
|
156
|
+
setVisible(attributes: string[]): this;
|
|
157
|
+
/** Laravel `makeVisible` — show attributes for this instance. */
|
|
158
|
+
makeVisible(...attributes: string[]): this;
|
|
159
|
+
/** Laravel `makeHidden` — hide attributes for this instance. */
|
|
160
|
+
makeHidden(...attributes: string[]): this;
|
|
161
|
+
/**
|
|
162
|
+
* Run a callback without touching timestamps (Laravel `Model::withoutTimestamps`).
|
|
163
|
+
*/
|
|
164
|
+
static withoutTimestamps<T>(this: typeof Model, callback: () => T | Promise<T>): Promise<T>;
|
|
165
|
+
/**
|
|
166
|
+
* Laravel `Model::withoutTouching` — skip parent `touch()` while callback runs.
|
|
167
|
+
* Pass model classes to limit which models ignore touch; omit for all.
|
|
168
|
+
*/
|
|
169
|
+
static withoutTouching<T>(this: typeof Model, callback: () => T | Promise<T>): Promise<T>;
|
|
170
|
+
static withoutTouching<T>(this: typeof Model, models: Array<typeof Model>, callback: () => T | Promise<T>): Promise<T>;
|
|
171
|
+
/** Whether touch is currently suppressed for this model class. */
|
|
172
|
+
static isIgnoringTouch(this: typeof Model): boolean;
|
|
173
|
+
/** Laravel `Model::preventLazyLoading`. */
|
|
174
|
+
static preventLazyLoading(prevent?: boolean): void;
|
|
175
|
+
/** Laravel `Model::preventSilentlyDiscardingAttributes`. */
|
|
176
|
+
static preventSilentlyDiscardingAttributes(prevent?: boolean): void;
|
|
177
|
+
/** Laravel `Model::preventAccessingMissingAttributes`. */
|
|
178
|
+
static preventAccessingMissingAttributes(prevent?: boolean): void;
|
|
179
|
+
/** Laravel `Model::shouldBeStrict` — enable/disable the strictness trio. */
|
|
180
|
+
static shouldBeStrict(should?: boolean): void;
|
|
181
|
+
/** Laravel `Model::addGlobalScope`. */
|
|
182
|
+
static addGlobalScope(this: typeof Model, nameOrScope: string | GlobalScopeCallback, scope?: GlobalScopeCallback): void;
|
|
183
|
+
/** Laravel `Model::addGlobalScope` removal helper. */
|
|
184
|
+
static removeGlobalScope(this: typeof Model, name: string): void;
|
|
185
|
+
/**
|
|
186
|
+
* Laravel `boot` — runs once per model class before first use.
|
|
187
|
+
* Prefer registering listeners in `booted()`.
|
|
188
|
+
*/
|
|
189
|
+
static boot(): void;
|
|
190
|
+
/**
|
|
191
|
+
* Laravel `booted` — runs once after `boot`. Typical place for `static::created(...)`.
|
|
192
|
+
*/
|
|
193
|
+
static booted(): void;
|
|
194
|
+
/** Ensure this model class has been booted. */
|
|
195
|
+
static bootIfNotBooted(): void;
|
|
196
|
+
/** Laravel `Model::observe`. */
|
|
197
|
+
static observe<T extends Model>(this: abstract new (...args: never[]) => T, observer: ModelObserver<T> | (new () => ModelObserver<T>) | Array<ModelObserver<T> | (new () => ModelObserver<T>)>): void;
|
|
198
|
+
/** Laravel `Model::withoutEvents`. */
|
|
199
|
+
static withoutEvents<T>(this: typeof Model, callback: () => T | Promise<T>): T | Promise<T>;
|
|
200
|
+
static retrieved(callback: ModelEventListener): void;
|
|
201
|
+
static creating(callback: ModelEventListener): void;
|
|
202
|
+
static created(callback: ModelEventListener): void;
|
|
203
|
+
static updating(callback: ModelEventListener): void;
|
|
204
|
+
static updated(callback: ModelEventListener): void;
|
|
205
|
+
static saving(callback: ModelEventListener): void;
|
|
206
|
+
static saved(callback: ModelEventListener): void;
|
|
207
|
+
static deleting(callback: ModelEventListener): void;
|
|
208
|
+
static deleted(callback: ModelEventListener): void;
|
|
209
|
+
static trashed(callback: ModelEventListener): void;
|
|
210
|
+
static forceDeleting(callback: ModelEventListener): void;
|
|
211
|
+
static forceDeleted(callback: ModelEventListener): void;
|
|
212
|
+
static restoring(callback: ModelEventListener): void;
|
|
213
|
+
static restored(callback: ModelEventListener): void;
|
|
214
|
+
static replicating(callback: ModelEventListener): void;
|
|
215
|
+
/** Fire a lifecycle event on this instance. */
|
|
216
|
+
fireModelEvent(event: ModelEventName): boolean | Promise<boolean>;
|
|
217
|
+
/** Resolve casts from `casts()` method or `$casts` property. */
|
|
218
|
+
static getCasts(): Record<string, CastDefinition>;
|
|
219
|
+
static castAttributes(attributes: Record<string, unknown>, direction: "get" | "set"): Record<string, unknown>;
|
|
220
|
+
static setConnection(connection: Connection): void;
|
|
221
|
+
static getConnection(): Connection;
|
|
222
|
+
/** Laravel `$model->setConnection($name)`. */
|
|
223
|
+
setConnection(connection: string | Connection): this;
|
|
224
|
+
/** Active connection for this instance (instance override → model → default). */
|
|
225
|
+
getConnection(): Connection;
|
|
226
|
+
static db(): DatabaseManager;
|
|
227
|
+
/**
|
|
228
|
+
* Laravel `Model::on($connection)` — same model, different named connection.
|
|
229
|
+
*/
|
|
230
|
+
static on<T extends typeof Model>(this: T, connection: string): ModelQuery<InstanceType<T>>;
|
|
231
|
+
/**
|
|
232
|
+
* Create a model query (honors `@UseBuilder` when present).
|
|
233
|
+
* Local scopes (`scopeActive` → `.active()`) are available via proxy.
|
|
234
|
+
*/
|
|
235
|
+
static newQuery<T extends typeof Model>(this: T, options?: ModelQueryOptions): ModelQuery<InstanceType<T>>;
|
|
236
|
+
/** Laravel `withoutGlobalScopes()`. */
|
|
237
|
+
static withoutGlobalScopes<T extends typeof Model>(this: T, names?: string[]): ModelQuery<InstanceType<T>>;
|
|
238
|
+
/** Laravel `withoutGlobalScope($name)`. */
|
|
239
|
+
static withoutGlobalScope<T extends typeof Model>(this: T, name: string): ModelQuery<InstanceType<T>>;
|
|
240
|
+
/** Laravel `Model::query()` — scoped `ModelQuery` (not a raw table builder). */
|
|
241
|
+
static query<T extends typeof Model>(this: T, options?: ModelQueryOptions): ModelQuery<InstanceType<T>>;
|
|
242
|
+
/** Laravel `Model::find`. */
|
|
243
|
+
static find<T extends typeof Model>(this: T, id: string | number): InstanceType<T> | null | Promise<InstanceType<T> | null>;
|
|
244
|
+
/** Laravel `getRouteKeyName()` — column used for implicit route binding. */
|
|
245
|
+
static getRouteKeyName(): string;
|
|
246
|
+
/**
|
|
247
|
+
* Laravel `resolveRouteBinding` — find by PK or custom `{param:column}` field.
|
|
248
|
+
*/
|
|
249
|
+
static resolveRouteBinding<T extends typeof Model>(this: T, value: string | number, field?: string): InstanceType<T> | null | Promise<InstanceType<T> | null>;
|
|
250
|
+
/**
|
|
251
|
+
* Laravel SoftDeletes `resolveSoftDeletableRouteBinding` — same as
|
|
252
|
+
* `resolveRouteBinding` but includes soft-deleted rows (`withTrashed()`).
|
|
253
|
+
* Used by the router when the route opts in via `withTrashed()`.
|
|
254
|
+
*/
|
|
255
|
+
static resolveSoftDeletableRouteBinding<T extends typeof Model>(this: T, value: string | number, field?: string): InstanceType<T> | null | Promise<InstanceType<T> | null>;
|
|
256
|
+
/** Laravel `Model::findOrFail`. */
|
|
257
|
+
static findOrFail<T extends typeof Model>(this: T, id: string | number): Promise<InstanceType<T>>;
|
|
258
|
+
/** Laravel `Model::all`. */
|
|
259
|
+
static all<T extends typeof Model>(this: T): Promise<OrmCollection<InstanceType<T>>>;
|
|
260
|
+
/**
|
|
261
|
+
* Laravel `Model::get` — same as `query().get()` / `all()`.
|
|
262
|
+
* Typed helper for autocomplete; Proxy also forwards other terminals.
|
|
263
|
+
*/
|
|
264
|
+
static get<T extends typeof Model>(this: T): OrmCollection<InstanceType<T>> | Promise<OrmCollection<InstanceType<T>>>;
|
|
265
|
+
/**
|
|
266
|
+
* Laravel `Model::pluck($column, $key = null)`.
|
|
267
|
+
* One column → list Collection; with `key` → keyed Record (see Collection.pluck).
|
|
268
|
+
*/
|
|
269
|
+
static pluck<T extends typeof Model>(this: T, column: string): Promise<Collection<unknown>>;
|
|
270
|
+
static pluck<T extends typeof Model>(this: T, column: string, key: string): Promise<Record<string, unknown>>;
|
|
271
|
+
/** SQLite-only sync `all()` — see `ModelQuery.getSync`. */
|
|
272
|
+
static allSync<T extends typeof Model>(this: T): OrmCollection<InstanceType<T>>;
|
|
273
|
+
/** SQLite-only sync `find` — see `ModelQuery.firstSync`. */
|
|
274
|
+
static findSync<T extends typeof Model>(this: T, id: string | number): InstanceType<T> | null;
|
|
275
|
+
/** Laravel `Model::where`. */
|
|
276
|
+
static where<T extends typeof Model>(this: T, callback: (query: ModelQuery<InstanceType<T>>) => void): ModelQuery<InstanceType<T>>;
|
|
277
|
+
static where<T extends typeof Model>(this: T, column: string, value: unknown): ModelQuery<InstanceType<T>>;
|
|
278
|
+
static where<T extends typeof Model>(this: T, column: string, op: string, value: unknown): ModelQuery<InstanceType<T>>;
|
|
279
|
+
/** Karobar-style multi-column LIKE search. */
|
|
280
|
+
static search<T extends typeof Model>(this: T, columns: string[], term: string): ModelQuery<InstanceType<T>>;
|
|
281
|
+
/** Start a new query and forward common builder methods (Laravel `__callStatic`). */
|
|
282
|
+
static orWhere<T extends typeof Model>(this: T, column: string, value: unknown): ModelQuery<InstanceType<T>>;
|
|
283
|
+
static orWhere<T extends typeof Model>(this: T, column: string, op: string, value: unknown): ModelQuery<InstanceType<T>>;
|
|
284
|
+
static whereIn<T extends typeof Model>(this: T, column: string, values: unknown[]): ModelQuery<InstanceType<T>>;
|
|
285
|
+
static whereNull<T extends typeof Model>(this: T, column: string): ModelQuery<InstanceType<T>>;
|
|
286
|
+
static whereNotNull<T extends typeof Model>(this: T, column: string): ModelQuery<InstanceType<T>>;
|
|
287
|
+
static orderBy<T extends typeof Model>(this: T, column: string, direction?: "asc" | "desc"): ModelQuery<InstanceType<T>>;
|
|
288
|
+
static orderByDesc<T extends typeof Model>(this: T, column: string): ModelQuery<InstanceType<T>>;
|
|
289
|
+
static orderByRaw<T extends typeof Model>(this: T, sql: string): ModelQuery<InstanceType<T>>;
|
|
290
|
+
/** Karobar alias for `orderByRaw`. */
|
|
291
|
+
static orderBySql<T extends typeof Model>(this: T, sql: string): ModelQuery<InstanceType<T>>;
|
|
292
|
+
static latest<T extends typeof Model>(this: T, column?: string): ModelQuery<InstanceType<T>>;
|
|
293
|
+
static oldest<T extends typeof Model>(this: T, column?: string): ModelQuery<InstanceType<T>>;
|
|
294
|
+
static limit<T extends typeof Model>(this: T, value: number): ModelQuery<InstanceType<T>>;
|
|
295
|
+
static take<T extends typeof Model>(this: T, value: number): ModelQuery<InstanceType<T>>;
|
|
296
|
+
static select<T extends typeof Model>(this: T, ...columns: string[]): ModelQuery<InstanceType<T>>;
|
|
297
|
+
/** Laravel `Model::whereDate`. */
|
|
298
|
+
static whereDate<T extends typeof Model>(this: T, column: string, value: DateInput): ModelQuery<InstanceType<T>>;
|
|
299
|
+
static whereDate<T extends typeof Model>(this: T, column: string, op: string, value: DateInput): ModelQuery<InstanceType<T>>;
|
|
300
|
+
/** Laravel `Model::whereNot(closure)`. */
|
|
301
|
+
static whereNot<T extends typeof Model>(this: T, callback: (query: ModelQuery<InstanceType<T>>) => void): ModelQuery<InstanceType<T>>;
|
|
302
|
+
/** Laravel `Model::orWhereNot(closure)`. */
|
|
303
|
+
static orWhereNot<T extends typeof Model>(this: T, callback: (query: ModelQuery<InstanceType<T>>) => void): ModelQuery<InstanceType<T>>;
|
|
304
|
+
/** Laravel `withTrashed()`. */
|
|
305
|
+
static withTrashed<T extends typeof Model>(this: T): ModelQuery<InstanceType<T>>;
|
|
306
|
+
/** Laravel `onlyTrashed()`. */
|
|
307
|
+
static onlyTrashed<T extends typeof Model>(this: T): ModelQuery<InstanceType<T>>;
|
|
308
|
+
/** Laravel `withoutTrashed()`. */
|
|
309
|
+
static withoutTrashed<T extends typeof Model>(this: T): ModelQuery<InstanceType<T>>;
|
|
310
|
+
/** `get()` returns plain row objects. Models are not built. */
|
|
311
|
+
static rows<T extends typeof Model>(this: T): ModelQuery<InstanceType<T>, "row">;
|
|
312
|
+
/** Eager-load relations (`with('posts')`, `with({ posts: (q) => q.where(…) })`). */
|
|
313
|
+
static with<T extends typeof Model>(this: T, ...relations: Array<string | string[] | Record<string, unknown>>): ModelQuery<InstanceType<T>>;
|
|
314
|
+
/** Laravel `Model::whereHas`. */
|
|
315
|
+
static whereHas<T extends typeof Model>(this: T, relation: string, callback?: (query: ModelQuery) => void): ModelQuery<InstanceType<T>>;
|
|
316
|
+
/** Laravel `Model::whereDoesntHave`. */
|
|
317
|
+
static whereDoesntHave<T extends typeof Model>(this: T, relation: string, callback?: (query: ModelQuery) => void): ModelQuery<InstanceType<T>>;
|
|
318
|
+
/** Laravel `Model::orWhereHas`. */
|
|
319
|
+
static orWhereHas<T extends typeof Model>(this: T, relation: string, callback?: (query: ModelQuery) => void): ModelQuery<InstanceType<T>>;
|
|
320
|
+
/** Laravel `Model::whereRelation`. */
|
|
321
|
+
static whereRelation<T extends typeof Model>(this: T, relation: string, column: string, opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
322
|
+
/** Laravel `Model::orWhereRelation`. */
|
|
323
|
+
static orWhereRelation<T extends typeof Model>(this: T, relation: string, column: string, opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
324
|
+
/** `withCount` — `'posts'`, `'posts as post_total'`, a string list, or `{ products: { as: 'productsCount' } }`. */
|
|
325
|
+
static withCount<T extends typeof Model>(this: T, ...relations: Array<string | string[] | Record<string, unknown>>): ModelQuery<InstanceType<T>>;
|
|
326
|
+
/** Laravel `Model::withSum`. */
|
|
327
|
+
static withSum<T extends typeof Model>(this: T, relation: string, column: string): ModelQuery<InstanceType<T>>;
|
|
328
|
+
static withAvg<T extends typeof Model>(this: T, relation: string, column: string): ModelQuery<InstanceType<T>>;
|
|
329
|
+
static withMin<T extends typeof Model>(this: T, relation: string, column: string): ModelQuery<InstanceType<T>>;
|
|
330
|
+
static withMax<T extends typeof Model>(this: T, relation: string, column: string): ModelQuery<InstanceType<T>>;
|
|
331
|
+
static withExists<T extends typeof Model>(this: T, ...relations: string[]): ModelQuery<InstanceType<T>>;
|
|
332
|
+
static withWhereHas<T extends typeof Model>(this: T, relation: string, callback?: (query: ModelQuery) => void): ModelQuery<InstanceType<T>>;
|
|
333
|
+
static whereBelongsTo<T extends typeof Model>(this: T, related: Model, relationName?: string): ModelQuery<InstanceType<T>>;
|
|
334
|
+
static whereAny<T extends typeof Model>(this: T, columns: string[], opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
335
|
+
static whereAll<T extends typeof Model>(this: T, columns: string[], opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
336
|
+
static whereNone<T extends typeof Model>(this: T, columns: string[], opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
337
|
+
static whereKey<T extends typeof Model>(this: T, id: string | number | Array<string | number>): ModelQuery<InstanceType<T>>;
|
|
338
|
+
/** Laravel `Model::whereUuid`. */
|
|
339
|
+
static whereUuid<T extends typeof Model>(this: T, column: string, value: string): ModelQuery<InstanceType<T>>;
|
|
340
|
+
/** Laravel `Model::whereUlid`. */
|
|
341
|
+
static whereUlid<T extends typeof Model>(this: T, column: string, value: string): ModelQuery<InstanceType<T>>;
|
|
342
|
+
/** Laravel `Model::join`. */
|
|
343
|
+
static join<T extends typeof Model>(this: T, table: string, first: string, op: string, second: string): ModelQuery<InstanceType<T>>;
|
|
344
|
+
/** Laravel `Model::leftJoin`. */
|
|
345
|
+
static leftJoin<T extends typeof Model>(this: T, table: string, first: string, op: string, second: string): ModelQuery<InstanceType<T>>;
|
|
346
|
+
/** Laravel `Model::paginate`. */
|
|
347
|
+
static paginate<T extends typeof Model>(this: T, perPage?: number, page?: number, options?: {
|
|
348
|
+
path?: string;
|
|
349
|
+
pageName?: string;
|
|
350
|
+
}): Promise<LengthAwarePaginator<InstanceType<T>>>;
|
|
351
|
+
/** Laravel `Model::cursorPaginate`. */
|
|
352
|
+
static cursorPaginate<T extends typeof Model>(this: T, perPage?: number, cursor?: string | null, options?: {
|
|
353
|
+
path?: string;
|
|
354
|
+
cursorName?: string;
|
|
355
|
+
}): Promise<CursorPaginator<InstanceType<T>>>;
|
|
356
|
+
/** Laravel `Model::create` (respects `$fillable` / `$guarded`). */
|
|
357
|
+
static create<T extends typeof Model>(this: T, attributes: Record<string, unknown>): InstanceType<T> | Promise<InstanceType<T>>;
|
|
358
|
+
/** Laravel `Model::forceCreate` — insert every given attribute, ignoring `$fillable`. */
|
|
359
|
+
static forceCreate<T extends typeof Model>(this: T, useAttrs: Record<string, unknown>): InstanceType<T> | Promise<InstanceType<T>>;
|
|
360
|
+
/** Laravel `firstOrNew`. */
|
|
361
|
+
static firstOrNew<T extends typeof Model>(this: T, attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<InstanceType<T>>;
|
|
362
|
+
/** Laravel `firstOrCreate`. */
|
|
363
|
+
static firstOrCreate<T extends typeof Model>(this: T, attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<InstanceType<T>>;
|
|
364
|
+
/** Laravel `updateOrCreate`. */
|
|
365
|
+
static updateOrCreate<T extends typeof Model>(this: T, attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<InstanceType<T>>;
|
|
366
|
+
/**
|
|
367
|
+
* Bulk insert. Delegates to `ModelQuery.insert` (timestamps stamped when enabled).
|
|
368
|
+
* Does not fire creating/created events — set tenant/client ids on the rows.
|
|
369
|
+
*/
|
|
370
|
+
static insert<T extends typeof Model>(this: T, values: Record<string, unknown> | Record<string, unknown>[]): Promise<boolean>;
|
|
371
|
+
/**
|
|
372
|
+
* Laravel `Model::upsert` — bulk insert-or-update on unique conflict.
|
|
373
|
+
* Delegates to `ModelQuery.upsert` (timestamps stamped when enabled).
|
|
374
|
+
*/
|
|
375
|
+
static upsert<T extends typeof Model>(this: T, values: Record<string, unknown> | Record<string, unknown>[], uniqueBy: string | string[], update?: string[] | null): Promise<number>;
|
|
376
|
+
/** Laravel `$model->fill($attributes)`. */
|
|
377
|
+
fill(attributes: Record<string, unknown>): this;
|
|
378
|
+
/** Laravel `$model->update($attributes)`. */
|
|
379
|
+
update(attributes: Record<string, unknown>): Promise<this>;
|
|
380
|
+
save(): this | Promise<this>;
|
|
381
|
+
/** Laravel `$model->saveQuietly()`. */
|
|
382
|
+
saveQuietly(): Promise<this>;
|
|
383
|
+
/** Laravel `$model->refresh()`. */
|
|
384
|
+
refresh(): Promise<this>;
|
|
385
|
+
/**
|
|
386
|
+
* Laravel-style refresh under row lock (`lockForUpdate`).
|
|
387
|
+
* Reloads this instance from a locked select of the same primary key.
|
|
388
|
+
*/
|
|
389
|
+
refreshForUpdate(): Promise<this>;
|
|
390
|
+
/** Laravel `$model->fresh()`. */
|
|
391
|
+
fresh(): Promise<this | null>;
|
|
392
|
+
/** Eager-load relations onto this model (`load('posts')` / constrained maps). */
|
|
393
|
+
load(...relations: Array<string | Record<string, unknown>>): Promise<this>;
|
|
394
|
+
/** Load only relations that are not already present. */
|
|
395
|
+
loadMissing(...relations: Array<string | Record<string, unknown>>): Promise<this>;
|
|
396
|
+
/** Laravel `$model->relationLoaded($key)`. */
|
|
397
|
+
relationLoaded(key: string): boolean;
|
|
398
|
+
/**
|
|
399
|
+
* Laravel `$model->touches($relation)` — whether `$touches` lists this relation.
|
|
400
|
+
*/
|
|
401
|
+
touches(relation: string): boolean;
|
|
402
|
+
/**
|
|
403
|
+
* Laravel `$model->touchOwners()` — touch each relation in `$touches`.
|
|
404
|
+
* Uses `relation.touch()` when available (BelongsTo / HasOne / HasMany);
|
|
405
|
+
* otherwise loads the related model and calls `touch()` on it.
|
|
406
|
+
*/
|
|
407
|
+
touchOwners(): Promise<void>;
|
|
408
|
+
/**
|
|
409
|
+
* Laravel `$model->touch()` — bump `updated_at` (no-op while `withoutTouching`).
|
|
410
|
+
* Saving also runs `$touches` / `touchOwners()` for listed relations.
|
|
411
|
+
*/
|
|
412
|
+
touch(): Promise<boolean>;
|
|
413
|
+
/**
|
|
414
|
+
* Relation query builder (`$model->product()` in Laravel).
|
|
415
|
+
*
|
|
416
|
+
* Define relations on `static relations` and declare the loaded property:
|
|
417
|
+
* `declare product: Product | null` — then use `model.product` after `with('product')`,
|
|
418
|
+
* and `model.related('product')` when you need the relation query.
|
|
419
|
+
*
|
|
420
|
+
* Legacy instance methods named `product()` remain supported via the prototype.
|
|
421
|
+
*/
|
|
422
|
+
related(name: string): unknown;
|
|
423
|
+
/** Laravel `$model->replicate()`. */
|
|
424
|
+
replicate(except?: string[]): this;
|
|
425
|
+
delete(): Promise<void>;
|
|
426
|
+
restore(): Promise<void>;
|
|
427
|
+
forceDelete(): Promise<void>;
|
|
428
|
+
/** Laravel `$model->deleteQuietly()`. */
|
|
429
|
+
deleteQuietly(): Promise<void>;
|
|
430
|
+
trashed(): boolean;
|
|
431
|
+
/** Laravel `$model->toArray()`. */
|
|
432
|
+
toArray(): Record<string, unknown>;
|
|
433
|
+
/** Laravel `$model->loadCount(...$relations)`. */
|
|
434
|
+
loadCount(...relations: string[]): Promise<this>;
|
|
435
|
+
/** Laravel `$model->loadSum($relation, $column)`. */
|
|
436
|
+
loadSum(relation: string, column: string): Promise<this>;
|
|
437
|
+
loadAvg(relation: string, column: string): Promise<this>;
|
|
438
|
+
loadMin(relation: string, column: string): Promise<this>;
|
|
439
|
+
loadMax(relation: string, column: string): Promise<this>;
|
|
440
|
+
/** Laravel `$model->loadExists(...$relations)`. */
|
|
441
|
+
loadExists(...relations: string[]): Promise<this>;
|
|
442
|
+
toJSON(): Record<string, unknown>;
|
|
443
|
+
/** Alias of {@link toJSON}. */
|
|
444
|
+
toJson(): Record<string, unknown>;
|
|
445
|
+
/** Laravel `$model->increment($column, $amount)`. */
|
|
446
|
+
increment(column: string, amount?: number): Promise<this>;
|
|
447
|
+
/** Laravel `$model->decrement($column, $amount)`. */
|
|
448
|
+
decrement(column: string, amount?: number): Promise<this>;
|
|
449
|
+
/** Laravel `Model::destroy($ids)`. */
|
|
450
|
+
static destroy<T extends typeof Model>(this: T, ids: Array<string | number> | string | number): Promise<number>;
|
|
451
|
+
/**
|
|
452
|
+
* Laravel `Model::forceDestroy($ids)` — permanent delete by key(s).
|
|
453
|
+
* Soft-delete models are found via `withTrashed()` so trashed rows are included.
|
|
454
|
+
*/
|
|
455
|
+
static forceDestroy<T extends typeof Model>(this: T, ids: Array<string | number> | string | number): Promise<number>;
|
|
456
|
+
/** Laravel `$this->hasMany(Related::class)`. */
|
|
457
|
+
hasMany<R extends ModelClass>(related: R, foreignKey?: string, localKey?: string): HasMany<InstanceType<R>>;
|
|
458
|
+
/** Laravel `$this->hasOne(Related::class)`. */
|
|
459
|
+
hasOne<R extends ModelClass>(related: R, foreignKey?: string, localKey?: string): HasOne<InstanceType<R>>;
|
|
460
|
+
/**
|
|
461
|
+
* Laravel `$this->hasManyThrough(Related::class, Through::class)`.
|
|
462
|
+
* Parent → Through (firstKey) → Related (secondKey).
|
|
463
|
+
*/
|
|
464
|
+
hasManyThrough<R extends ModelClass, TThrough extends ModelClass>(related: R, through: TThrough, firstKey?: string, secondKey?: string, localKey?: string, secondLocalKey?: string): HasManyThrough<InstanceType<R>>;
|
|
465
|
+
/**
|
|
466
|
+
* Laravel `$this->hasOneThrough(Related::class, Through::class)`.
|
|
467
|
+
*/
|
|
468
|
+
hasOneThrough<R extends ModelClass, TThrough extends ModelClass>(related: R, through: TThrough, firstKey?: string, secondKey?: string, localKey?: string, secondLocalKey?: string): HasOneThrough<InstanceType<R>>;
|
|
469
|
+
/** Laravel `$this->belongsTo(Related::class)`. */
|
|
470
|
+
belongsTo<R extends ModelClass>(related: R, foreignKey?: string, ownerKey?: string): BelongsTo<InstanceType<R>>;
|
|
471
|
+
/** Laravel `$this->belongsToMany(Related::class, pivot)`. */
|
|
472
|
+
belongsToMany<R extends ModelClass>(related: R, table?: string, foreignPivotKey?: string, relatedPivotKey?: string): BelongsToMany<InstanceType<R>>;
|
|
473
|
+
/**
|
|
474
|
+
* Polymorphic many-to-many (`model_has_roles`-style pivots).
|
|
475
|
+
* Third argument may be the pivot table name or an options bag (tenant/legacy morph types).
|
|
476
|
+
*/
|
|
477
|
+
morphToMany<R extends ModelClass>(related: R, name: string, tableOrOptions?: string | MorphToManyOptions, foreignPivotKey?: string, relatedPivotKey?: string): MorphToMany<InstanceType<R>>;
|
|
478
|
+
/** Laravel `$this->morphMany(Related::class, name)`. */
|
|
479
|
+
morphMany<R extends ModelClass>(related: R, name: string, type?: string, id?: string, localKey?: string): MorphMany<InstanceType<R>>;
|
|
480
|
+
/** Laravel `$this->morphOne(Related::class, name)`. */
|
|
481
|
+
morphOne<R extends ModelClass>(related: R, name: string, type?: string, id?: string, localKey?: string): MorphOne<InstanceType<R>>;
|
|
482
|
+
/** Laravel `$this->morphTo($name)`. */
|
|
483
|
+
morphTo(name: string, type?: string, id?: string, ownerKey?: string): MorphTo;
|
|
484
|
+
}
|
|
485
|
+
/** True when `value` is a Model subclass constructor (O(1) prototype check). */
|
|
486
|
+
export declare function isModelCtor(value: unknown): value is ModelClass;
|
|
487
|
+
export { BelongsTo, BelongsToMany, HasMany, HasManyThrough, HasOne, HasOneThrough, MorphMany, MorphOne, MorphTo, MorphToMany, clearMorphMap, morphMap, type MorphToManyOptions, } from "./relations.js";
|
|
488
|
+
export { eagerLoadAggregates, eagerLoadModels, type EagerAggregateSpec, } from "./eager.js";
|
|
489
|
+
export { ModelQuery } from "./model-query.js";
|
|
490
|
+
export { LazyLoadingViolationException, MassAssignmentException, MissingAttributeException, resetModelStrictnessForTests, } from "./model-strictness.js";
|