@bunyad/orm 0.1.0-alpha.0 → 0.2.0-beta.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/README.md +3 -3
- package/dist/concerns.d.ts +2 -2
- package/dist/factory.d.ts +3 -3
- package/dist/model-events.d.ts +2 -2
- package/dist/model-events.js +1 -1
- package/dist/model-query.d.ts +55 -55
- package/dist/model-query.js +51 -51
- package/dist/model-strictness.d.ts +2 -3
- package/dist/model-strictness.js +2 -3
- package/dist/model.d.ts +106 -106
- package/dist/model.js +103 -103
- package/dist/orm-collection.d.ts +1 -1
- package/dist/orm-collection.js +1 -1
- package/dist/relations.d.ts +4 -4
- package/dist/relations.js +3 -3
- package/dist/scopes.d.ts +1 -2
- package/dist/scopes.js +1 -2
- package/package.json +3 -3
package/dist/model.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ export declare class Model {
|
|
|
81
81
|
/** When false, `save()` skips `created_at` / `updated_at`. */
|
|
82
82
|
static timestamps: boolean;
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
84
|
+
* `$casts` property — prefer `static casts()` when adding enums / Attribute.
|
|
85
85
|
* May be a plain object or a method returning the map.
|
|
86
86
|
*/
|
|
87
87
|
static casts: Record<string, CastDefinition> | (() => Record<string, CastDefinition>);
|
|
@@ -92,22 +92,22 @@ export declare class Model {
|
|
|
92
92
|
*/
|
|
93
93
|
static relations: RelationsMap;
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
95
|
+
* `$touches` — relation names whose related models get `touch()` after
|
|
96
96
|
* this model is saved (or soft-deleted). Honor `withoutTouching`.
|
|
97
97
|
*/
|
|
98
98
|
static touches: string[];
|
|
99
|
-
/**
|
|
99
|
+
/** `$hidden`. */
|
|
100
100
|
static hidden: string[];
|
|
101
|
-
/**
|
|
101
|
+
/** `$visible` allow-list (empty = all non-hidden). */
|
|
102
102
|
static visible: string[];
|
|
103
|
-
/**
|
|
103
|
+
/** `$appends` — accessors included in `toArray()`. */
|
|
104
104
|
static appends: string[];
|
|
105
|
-
/**
|
|
105
|
+
/** `$fillable`. */
|
|
106
106
|
static fillable: readonly string[] | string[];
|
|
107
|
-
/**
|
|
107
|
+
/** `$guarded` — default guard all until fillable is set. */
|
|
108
108
|
static guarded: readonly string[] | string[];
|
|
109
109
|
id: string | number;
|
|
110
|
-
/**
|
|
110
|
+
/** `$exists` — true after retrieve / successful insert. */
|
|
111
111
|
get exists(): boolean;
|
|
112
112
|
set exists(value: boolean);
|
|
113
113
|
constructor(attributes?: Record<string, unknown>);
|
|
@@ -121,81 +121,81 @@ export declare class Model {
|
|
|
121
121
|
/** Current attribute bag (non-function own properties). */
|
|
122
122
|
getAttributes(): Record<string, unknown>;
|
|
123
123
|
/**
|
|
124
|
-
*
|
|
124
|
+
* `getAttribute` — throws when `preventAccessingMissingAttributes` is on
|
|
125
125
|
* and the key was not retrieved / does not exist (relations exempt).
|
|
126
126
|
*/
|
|
127
127
|
getAttribute(key: string): unknown;
|
|
128
|
-
/**
|
|
128
|
+
/** `isDirty`. */
|
|
129
129
|
isDirty(...attributes: string[]): boolean;
|
|
130
|
-
/**
|
|
130
|
+
/** `isClean`. */
|
|
131
131
|
isClean(...attributes: string[]): boolean;
|
|
132
|
-
/**
|
|
132
|
+
/** `getDirty`. */
|
|
133
133
|
getDirty(): Record<string, unknown>;
|
|
134
|
-
/**
|
|
134
|
+
/** `getOriginal`. */
|
|
135
135
|
getOriginal(): Record<string, unknown>;
|
|
136
136
|
getOriginal(key: string): unknown;
|
|
137
|
-
/**
|
|
137
|
+
/** `getChanges` — attributes changed by the last save. */
|
|
138
138
|
getChanges(): Record<string, unknown>;
|
|
139
|
-
/**
|
|
139
|
+
/** `wasChanged`. */
|
|
140
140
|
wasChanged(...attributes: string[]): boolean;
|
|
141
|
-
/**
|
|
141
|
+
/** `wasRecentlyCreated`. */
|
|
142
142
|
wasRecentlyCreated(): boolean;
|
|
143
|
-
/**
|
|
143
|
+
/** `append`. */
|
|
144
144
|
append(...attributes: string[]): this;
|
|
145
|
-
/**
|
|
145
|
+
/** `setAppends`. */
|
|
146
146
|
setAppends(attributes: string[]): this;
|
|
147
|
-
/**
|
|
147
|
+
/** `getAppends`. */
|
|
148
148
|
getAppends(): string[];
|
|
149
|
-
/**
|
|
149
|
+
/** `getHidden`. */
|
|
150
150
|
getHidden(): string[];
|
|
151
|
-
/**
|
|
151
|
+
/** `getVisible`. */
|
|
152
152
|
getVisible(): string[];
|
|
153
|
-
/**
|
|
153
|
+
/** `setHidden`. */
|
|
154
154
|
setHidden(attributes: string[]): this;
|
|
155
|
-
/**
|
|
155
|
+
/** `setVisible`. */
|
|
156
156
|
setVisible(attributes: string[]): this;
|
|
157
|
-
/**
|
|
157
|
+
/** `makeVisible` — show attributes for this instance. */
|
|
158
158
|
makeVisible(...attributes: string[]): this;
|
|
159
|
-
/**
|
|
159
|
+
/** `makeHidden` — hide attributes for this instance. */
|
|
160
160
|
makeHidden(...attributes: string[]): this;
|
|
161
161
|
/**
|
|
162
|
-
* Run a callback without touching timestamps (
|
|
162
|
+
* Run a callback without touching timestamps (`Model::withoutTimestamps`).
|
|
163
163
|
*/
|
|
164
164
|
static withoutTimestamps<T>(this: typeof Model, callback: () => T | Promise<T>): Promise<T>;
|
|
165
165
|
/**
|
|
166
|
-
*
|
|
166
|
+
* `Model::withoutTouching` — skip parent `touch()` while callback runs.
|
|
167
167
|
* Pass model classes to limit which models ignore touch; omit for all.
|
|
168
168
|
*/
|
|
169
169
|
static withoutTouching<T>(this: typeof Model, callback: () => T | Promise<T>): Promise<T>;
|
|
170
170
|
static withoutTouching<T>(this: typeof Model, models: Array<typeof Model>, callback: () => T | Promise<T>): Promise<T>;
|
|
171
171
|
/** Whether touch is currently suppressed for this model class. */
|
|
172
172
|
static isIgnoringTouch(this: typeof Model): boolean;
|
|
173
|
-
/**
|
|
173
|
+
/** `Model::preventLazyLoading`. */
|
|
174
174
|
static preventLazyLoading(prevent?: boolean): void;
|
|
175
|
-
/**
|
|
175
|
+
/** `Model::preventSilentlyDiscardingAttributes`. */
|
|
176
176
|
static preventSilentlyDiscardingAttributes(prevent?: boolean): void;
|
|
177
|
-
/**
|
|
177
|
+
/** `Model::preventAccessingMissingAttributes`. */
|
|
178
178
|
static preventAccessingMissingAttributes(prevent?: boolean): void;
|
|
179
|
-
/**
|
|
179
|
+
/** `Model::shouldBeStrict` — enable/disable the strictness trio. */
|
|
180
180
|
static shouldBeStrict(should?: boolean): void;
|
|
181
|
-
/**
|
|
181
|
+
/** `Model::addGlobalScope`. */
|
|
182
182
|
static addGlobalScope(this: typeof Model, nameOrScope: string | GlobalScopeCallback, scope?: GlobalScopeCallback): void;
|
|
183
|
-
/**
|
|
183
|
+
/** `Model::addGlobalScope` removal helper. */
|
|
184
184
|
static removeGlobalScope(this: typeof Model, name: string): void;
|
|
185
185
|
/**
|
|
186
|
-
*
|
|
186
|
+
* `boot` — runs once per model class before first use.
|
|
187
187
|
* Prefer registering listeners in `booted()`.
|
|
188
188
|
*/
|
|
189
189
|
static boot(): void;
|
|
190
190
|
/**
|
|
191
|
-
*
|
|
191
|
+
* `booted` — runs once after `boot`. Typical place for `static::created(...)`.
|
|
192
192
|
*/
|
|
193
193
|
static booted(): void;
|
|
194
194
|
/** Ensure this model class has been booted. */
|
|
195
195
|
static bootIfNotBooted(): void;
|
|
196
|
-
/**
|
|
196
|
+
/** `Model::observe`. */
|
|
197
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
|
-
/**
|
|
198
|
+
/** `Model::withoutEvents`. */
|
|
199
199
|
static withoutEvents<T>(this: typeof Model, callback: () => T | Promise<T>): T | Promise<T>;
|
|
200
200
|
static retrieved(callback: ModelEventListener): void;
|
|
201
201
|
static creating(callback: ModelEventListener): void;
|
|
@@ -219,13 +219,13 @@ export declare class Model {
|
|
|
219
219
|
static castAttributes(attributes: Record<string, unknown>, direction: "get" | "set"): Record<string, unknown>;
|
|
220
220
|
static setConnection(connection: Connection): void;
|
|
221
221
|
static getConnection(): Connection;
|
|
222
|
-
/**
|
|
222
|
+
/** `$model->setConnection($name)`. */
|
|
223
223
|
setConnection(connection: string | Connection): this;
|
|
224
224
|
/** Active connection for this instance (instance override → model → default). */
|
|
225
225
|
getConnection(): Connection;
|
|
226
226
|
static db(): DatabaseManager;
|
|
227
227
|
/**
|
|
228
|
-
*
|
|
228
|
+
* `Model::on($connection)` — same model, different named connection.
|
|
229
229
|
*/
|
|
230
230
|
static on<T extends typeof Model>(this: T, connection: string): ModelQuery<InstanceType<T>>;
|
|
231
231
|
/**
|
|
@@ -233,37 +233,37 @@ export declare class Model {
|
|
|
233
233
|
* Local scopes (`scopeActive` → `.active()`) are available via proxy.
|
|
234
234
|
*/
|
|
235
235
|
static newQuery<T extends typeof Model>(this: T, options?: ModelQueryOptions): ModelQuery<InstanceType<T>>;
|
|
236
|
-
/**
|
|
236
|
+
/** `withoutGlobalScopes()`. */
|
|
237
237
|
static withoutGlobalScopes<T extends typeof Model>(this: T, names?: string[]): ModelQuery<InstanceType<T>>;
|
|
238
|
-
/**
|
|
238
|
+
/** `withoutGlobalScope($name)`. */
|
|
239
239
|
static withoutGlobalScope<T extends typeof Model>(this: T, name: string): ModelQuery<InstanceType<T>>;
|
|
240
|
-
/**
|
|
240
|
+
/** `Model::query()` — scoped `ModelQuery` (not a raw table builder). */
|
|
241
241
|
static query<T extends typeof Model>(this: T, options?: ModelQueryOptions): ModelQuery<InstanceType<T>>;
|
|
242
|
-
/**
|
|
242
|
+
/** `Model::find`. */
|
|
243
243
|
static find<T extends typeof Model>(this: T, id: string | number): InstanceType<T> | null | Promise<InstanceType<T> | null>;
|
|
244
|
-
/**
|
|
244
|
+
/** `getRouteKeyName()` — column used for implicit route binding. */
|
|
245
245
|
static getRouteKeyName(): string;
|
|
246
246
|
/**
|
|
247
|
-
*
|
|
247
|
+
* `resolveRouteBinding` — find by PK or custom `{param:column}` field.
|
|
248
248
|
*/
|
|
249
249
|
static resolveRouteBinding<T extends typeof Model>(this: T, value: string | number, field?: string): InstanceType<T> | null | Promise<InstanceType<T> | null>;
|
|
250
250
|
/**
|
|
251
|
-
*
|
|
251
|
+
* `resolveSoftDeletableRouteBinding` — same as
|
|
252
252
|
* `resolveRouteBinding` but includes soft-deleted rows (`withTrashed()`).
|
|
253
253
|
* Used by the router when the route opts in via `withTrashed()`.
|
|
254
254
|
*/
|
|
255
255
|
static resolveSoftDeletableRouteBinding<T extends typeof Model>(this: T, value: string | number, field?: string): InstanceType<T> | null | Promise<InstanceType<T> | null>;
|
|
256
|
-
/**
|
|
256
|
+
/** `Model::findOrFail`. */
|
|
257
257
|
static findOrFail<T extends typeof Model>(this: T, id: string | number): Promise<InstanceType<T>>;
|
|
258
|
-
/**
|
|
258
|
+
/** `Model::all`. */
|
|
259
259
|
static all<T extends typeof Model>(this: T): Promise<OrmCollection<InstanceType<T>>>;
|
|
260
260
|
/**
|
|
261
|
-
*
|
|
261
|
+
* `Model::get` — same as `query().get()` / `all()`.
|
|
262
262
|
* Typed helper for autocomplete; Proxy also forwards other terminals.
|
|
263
263
|
*/
|
|
264
264
|
static get<T extends typeof Model>(this: T): OrmCollection<InstanceType<T>> | Promise<OrmCollection<InstanceType<T>>>;
|
|
265
265
|
/**
|
|
266
|
-
*
|
|
266
|
+
* `Model::pluck($column, $key = null)`.
|
|
267
267
|
* One column → list Collection; with `key` → keyed Record (see Collection.pluck).
|
|
268
268
|
*/
|
|
269
269
|
static pluck<T extends typeof Model>(this: T, column: string): Promise<Collection<unknown>>;
|
|
@@ -272,13 +272,13 @@ export declare class Model {
|
|
|
272
272
|
static allSync<T extends typeof Model>(this: T): OrmCollection<InstanceType<T>>;
|
|
273
273
|
/** SQLite-only sync `find` — see `ModelQuery.firstSync`. */
|
|
274
274
|
static findSync<T extends typeof Model>(this: T, id: string | number): InstanceType<T> | null;
|
|
275
|
-
/**
|
|
275
|
+
/** `Model::where`. */
|
|
276
276
|
static where<T extends typeof Model>(this: T, callback: (query: ModelQuery<InstanceType<T>>) => void): ModelQuery<InstanceType<T>>;
|
|
277
277
|
static where<T extends typeof Model>(this: T, column: string, value: unknown): ModelQuery<InstanceType<T>>;
|
|
278
278
|
static where<T extends typeof Model>(this: T, column: string, op: string, value: unknown): ModelQuery<InstanceType<T>>;
|
|
279
279
|
/** Karobar-style multi-column LIKE search. */
|
|
280
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 (
|
|
281
|
+
/** Start a new query and forward common builder methods (`__callStatic`). */
|
|
282
282
|
static orWhere<T extends typeof Model>(this: T, column: string, value: unknown): ModelQuery<InstanceType<T>>;
|
|
283
283
|
static orWhere<T extends typeof Model>(this: T, column: string, op: string, value: unknown): ModelQuery<InstanceType<T>>;
|
|
284
284
|
static whereIn<T extends typeof Model>(this: T, column: string, values: unknown[]): ModelQuery<InstanceType<T>>;
|
|
@@ -294,36 +294,36 @@ export declare class Model {
|
|
|
294
294
|
static limit<T extends typeof Model>(this: T, value: number): ModelQuery<InstanceType<T>>;
|
|
295
295
|
static take<T extends typeof Model>(this: T, value: number): ModelQuery<InstanceType<T>>;
|
|
296
296
|
static select<T extends typeof Model>(this: T, ...columns: string[]): ModelQuery<InstanceType<T>>;
|
|
297
|
-
/**
|
|
297
|
+
/** `Model::whereDate`. */
|
|
298
298
|
static whereDate<T extends typeof Model>(this: T, column: string, value: DateInput): ModelQuery<InstanceType<T>>;
|
|
299
299
|
static whereDate<T extends typeof Model>(this: T, column: string, op: string, value: DateInput): ModelQuery<InstanceType<T>>;
|
|
300
|
-
/**
|
|
300
|
+
/** `Model::whereNot(closure)`. */
|
|
301
301
|
static whereNot<T extends typeof Model>(this: T, callback: (query: ModelQuery<InstanceType<T>>) => void): ModelQuery<InstanceType<T>>;
|
|
302
|
-
/**
|
|
302
|
+
/** `Model::orWhereNot(closure)`. */
|
|
303
303
|
static orWhereNot<T extends typeof Model>(this: T, callback: (query: ModelQuery<InstanceType<T>>) => void): ModelQuery<InstanceType<T>>;
|
|
304
|
-
/**
|
|
304
|
+
/** `withTrashed()`. */
|
|
305
305
|
static withTrashed<T extends typeof Model>(this: T): ModelQuery<InstanceType<T>>;
|
|
306
|
-
/**
|
|
306
|
+
/** `onlyTrashed()`. */
|
|
307
307
|
static onlyTrashed<T extends typeof Model>(this: T): ModelQuery<InstanceType<T>>;
|
|
308
|
-
/**
|
|
308
|
+
/** `withoutTrashed()`. */
|
|
309
309
|
static withoutTrashed<T extends typeof Model>(this: T): ModelQuery<InstanceType<T>>;
|
|
310
310
|
/** `get()` returns plain row objects. Models are not built. */
|
|
311
311
|
static rows<T extends typeof Model>(this: T): ModelQuery<InstanceType<T>, "row">;
|
|
312
312
|
/** Eager-load relations (`with('posts')`, `with({ posts: (q) => q.where(…) })`). */
|
|
313
313
|
static with<T extends typeof Model>(this: T, ...relations: Array<string | string[] | Record<string, unknown>>): ModelQuery<InstanceType<T>>;
|
|
314
|
-
/**
|
|
314
|
+
/** `Model::whereHas`. */
|
|
315
315
|
static whereHas<T extends typeof Model>(this: T, relation: string, callback?: (query: ModelQuery) => void): ModelQuery<InstanceType<T>>;
|
|
316
|
-
/**
|
|
316
|
+
/** `Model::whereDoesntHave`. */
|
|
317
317
|
static whereDoesntHave<T extends typeof Model>(this: T, relation: string, callback?: (query: ModelQuery) => void): ModelQuery<InstanceType<T>>;
|
|
318
|
-
/**
|
|
318
|
+
/** `Model::orWhereHas`. */
|
|
319
319
|
static orWhereHas<T extends typeof Model>(this: T, relation: string, callback?: (query: ModelQuery) => void): ModelQuery<InstanceType<T>>;
|
|
320
|
-
/**
|
|
320
|
+
/** `Model::whereRelation`. */
|
|
321
321
|
static whereRelation<T extends typeof Model>(this: T, relation: string, column: string, opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
322
|
-
/**
|
|
322
|
+
/** `Model::orWhereRelation`. */
|
|
323
323
|
static orWhereRelation<T extends typeof Model>(this: T, relation: string, column: string, opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
324
324
|
/** `withCount` — `'posts'`, `'posts as post_total'`, a string list, or `{ products: { as: 'productsCount' } }`. */
|
|
325
325
|
static withCount<T extends typeof Model>(this: T, ...relations: Array<string | string[] | Record<string, unknown>>): ModelQuery<InstanceType<T>>;
|
|
326
|
-
/**
|
|
326
|
+
/** `Model::withSum`. */
|
|
327
327
|
static withSum<T extends typeof Model>(this: T, relation: string, column: string): ModelQuery<InstanceType<T>>;
|
|
328
328
|
static withAvg<T extends typeof Model>(this: T, relation: string, column: string): ModelQuery<InstanceType<T>>;
|
|
329
329
|
static withMin<T extends typeof Model>(this: T, relation: string, column: string): ModelQuery<InstanceType<T>>;
|
|
@@ -335,33 +335,33 @@ export declare class Model {
|
|
|
335
335
|
static whereAll<T extends typeof Model>(this: T, columns: string[], opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
336
336
|
static whereNone<T extends typeof Model>(this: T, columns: string[], opOrValue: unknown, value?: unknown): ModelQuery<InstanceType<T>>;
|
|
337
337
|
static whereKey<T extends typeof Model>(this: T, id: string | number | Array<string | number>): ModelQuery<InstanceType<T>>;
|
|
338
|
-
/**
|
|
338
|
+
/** `Model::whereUuid`. */
|
|
339
339
|
static whereUuid<T extends typeof Model>(this: T, column: string, value: string): ModelQuery<InstanceType<T>>;
|
|
340
|
-
/**
|
|
340
|
+
/** `Model::whereUlid`. */
|
|
341
341
|
static whereUlid<T extends typeof Model>(this: T, column: string, value: string): ModelQuery<InstanceType<T>>;
|
|
342
|
-
/**
|
|
342
|
+
/** `Model::join`. */
|
|
343
343
|
static join<T extends typeof Model>(this: T, table: string, first: string, op: string, second: string): ModelQuery<InstanceType<T>>;
|
|
344
|
-
/**
|
|
344
|
+
/** `Model::leftJoin`. */
|
|
345
345
|
static leftJoin<T extends typeof Model>(this: T, table: string, first: string, op: string, second: string): ModelQuery<InstanceType<T>>;
|
|
346
|
-
/**
|
|
346
|
+
/** `Model::paginate`. */
|
|
347
347
|
static paginate<T extends typeof Model>(this: T, perPage?: number, page?: number, options?: {
|
|
348
348
|
path?: string;
|
|
349
349
|
pageName?: string;
|
|
350
350
|
}): Promise<LengthAwarePaginator<InstanceType<T>>>;
|
|
351
|
-
/**
|
|
351
|
+
/** `Model::cursorPaginate`. */
|
|
352
352
|
static cursorPaginate<T extends typeof Model>(this: T, perPage?: number, cursor?: string | null, options?: {
|
|
353
353
|
path?: string;
|
|
354
354
|
cursorName?: string;
|
|
355
355
|
}): Promise<CursorPaginator<InstanceType<T>>>;
|
|
356
|
-
/**
|
|
356
|
+
/** `Model::create` (respects `$fillable` / `$guarded`). */
|
|
357
357
|
static create<T extends typeof Model>(this: T, attributes: Record<string, unknown>): InstanceType<T> | Promise<InstanceType<T>>;
|
|
358
|
-
/**
|
|
358
|
+
/** `Model::forceCreate` — insert every given attribute, ignoring `$fillable`. */
|
|
359
359
|
static forceCreate<T extends typeof Model>(this: T, useAttrs: Record<string, unknown>): InstanceType<T> | Promise<InstanceType<T>>;
|
|
360
|
-
/**
|
|
360
|
+
/** `firstOrNew`. */
|
|
361
361
|
static firstOrNew<T extends typeof Model>(this: T, attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<InstanceType<T>>;
|
|
362
|
-
/**
|
|
362
|
+
/** `firstOrCreate`. */
|
|
363
363
|
static firstOrCreate<T extends typeof Model>(this: T, attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<InstanceType<T>>;
|
|
364
|
-
/**
|
|
364
|
+
/** `updateOrCreate`. */
|
|
365
365
|
static updateOrCreate<T extends typeof Model>(this: T, attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<InstanceType<T>>;
|
|
366
366
|
/**
|
|
367
367
|
* Bulk insert. Delegates to `ModelQuery.insert` (timestamps stamped when enabled).
|
|
@@ -369,49 +369,49 @@ export declare class Model {
|
|
|
369
369
|
*/
|
|
370
370
|
static insert<T extends typeof Model>(this: T, values: Record<string, unknown> | Record<string, unknown>[]): Promise<boolean>;
|
|
371
371
|
/**
|
|
372
|
-
*
|
|
372
|
+
* `Model::upsert` — bulk insert-or-update on unique conflict.
|
|
373
373
|
* Delegates to `ModelQuery.upsert` (timestamps stamped when enabled).
|
|
374
374
|
*/
|
|
375
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
|
-
/**
|
|
376
|
+
/** `$model->fill($attributes)`. */
|
|
377
377
|
fill(attributes: Record<string, unknown>): this;
|
|
378
|
-
/**
|
|
378
|
+
/** `$model->update($attributes)`. */
|
|
379
379
|
update(attributes: Record<string, unknown>): Promise<this>;
|
|
380
380
|
save(): this | Promise<this>;
|
|
381
|
-
/**
|
|
381
|
+
/** `$model->saveQuietly()`. */
|
|
382
382
|
saveQuietly(): Promise<this>;
|
|
383
|
-
/**
|
|
383
|
+
/** `$model->refresh()`. */
|
|
384
384
|
refresh(): Promise<this>;
|
|
385
385
|
/**
|
|
386
|
-
*
|
|
386
|
+
* Refresh under row lock (`lockForUpdate`).
|
|
387
387
|
* Reloads this instance from a locked select of the same primary key.
|
|
388
388
|
*/
|
|
389
389
|
refreshForUpdate(): Promise<this>;
|
|
390
|
-
/**
|
|
390
|
+
/** `$model->fresh()`. */
|
|
391
391
|
fresh(): Promise<this | null>;
|
|
392
392
|
/** Eager-load relations onto this model (`load('posts')` / constrained maps). */
|
|
393
393
|
load(...relations: Array<string | Record<string, unknown>>): Promise<this>;
|
|
394
394
|
/** Load only relations that are not already present. */
|
|
395
395
|
loadMissing(...relations: Array<string | Record<string, unknown>>): Promise<this>;
|
|
396
|
-
/**
|
|
396
|
+
/** `$model->relationLoaded($key)`. */
|
|
397
397
|
relationLoaded(key: string): boolean;
|
|
398
398
|
/**
|
|
399
|
-
*
|
|
399
|
+
* `$model->touches($relation)` — whether `$touches` lists this relation.
|
|
400
400
|
*/
|
|
401
401
|
touches(relation: string): boolean;
|
|
402
402
|
/**
|
|
403
|
-
*
|
|
403
|
+
* `$model->touchOwners()` — touch each relation in `$touches`.
|
|
404
404
|
* Uses `relation.touch()` when available (BelongsTo / HasOne / HasMany);
|
|
405
405
|
* otherwise loads the related model and calls `touch()` on it.
|
|
406
406
|
*/
|
|
407
407
|
touchOwners(): Promise<void>;
|
|
408
408
|
/**
|
|
409
|
-
*
|
|
409
|
+
* `$model->touch()` — bump `updated_at` (no-op while `withoutTouching`).
|
|
410
410
|
* Saving also runs `$touches` / `touchOwners()` for listed relations.
|
|
411
411
|
*/
|
|
412
412
|
touch(): Promise<boolean>;
|
|
413
413
|
/**
|
|
414
|
-
* Relation query builder (`$model->product()`
|
|
414
|
+
* Relation query builder (`$model->product()`).
|
|
415
415
|
*
|
|
416
416
|
* Define relations on `static relations` and declare the loaded property:
|
|
417
417
|
* `declare product: Product | null` — then use `model.product` after `with('product')`,
|
|
@@ -420,66 +420,66 @@ export declare class Model {
|
|
|
420
420
|
* Legacy instance methods named `product()` remain supported via the prototype.
|
|
421
421
|
*/
|
|
422
422
|
related(name: string): unknown;
|
|
423
|
-
/**
|
|
423
|
+
/** `$model->replicate()`. */
|
|
424
424
|
replicate(except?: string[]): this;
|
|
425
425
|
delete(): Promise<void>;
|
|
426
426
|
restore(): Promise<void>;
|
|
427
427
|
forceDelete(): Promise<void>;
|
|
428
|
-
/**
|
|
428
|
+
/** `$model->deleteQuietly()`. */
|
|
429
429
|
deleteQuietly(): Promise<void>;
|
|
430
430
|
trashed(): boolean;
|
|
431
|
-
/**
|
|
431
|
+
/** `$model->toArray()`. */
|
|
432
432
|
toArray(): Record<string, unknown>;
|
|
433
|
-
/**
|
|
433
|
+
/** `$model->loadCount(...$relations)`. */
|
|
434
434
|
loadCount(...relations: string[]): Promise<this>;
|
|
435
|
-
/**
|
|
435
|
+
/** `$model->loadSum($relation, $column)`. */
|
|
436
436
|
loadSum(relation: string, column: string): Promise<this>;
|
|
437
437
|
loadAvg(relation: string, column: string): Promise<this>;
|
|
438
438
|
loadMin(relation: string, column: string): Promise<this>;
|
|
439
439
|
loadMax(relation: string, column: string): Promise<this>;
|
|
440
|
-
/**
|
|
440
|
+
/** `$model->loadExists(...$relations)`. */
|
|
441
441
|
loadExists(...relations: string[]): Promise<this>;
|
|
442
442
|
toJSON(): Record<string, unknown>;
|
|
443
443
|
/** Alias of {@link toJSON}. */
|
|
444
444
|
toJson(): Record<string, unknown>;
|
|
445
|
-
/**
|
|
445
|
+
/** `$model->increment($column, $amount)`. */
|
|
446
446
|
increment(column: string, amount?: number): Promise<this>;
|
|
447
|
-
/**
|
|
447
|
+
/** `$model->decrement($column, $amount)`. */
|
|
448
448
|
decrement(column: string, amount?: number): Promise<this>;
|
|
449
|
-
/**
|
|
449
|
+
/** `Model::destroy($ids)`. */
|
|
450
450
|
static destroy<T extends typeof Model>(this: T, ids: Array<string | number> | string | number): Promise<number>;
|
|
451
451
|
/**
|
|
452
|
-
*
|
|
452
|
+
* `Model::forceDestroy($ids)` — permanent delete by key(s).
|
|
453
453
|
* Soft-delete models are found via `withTrashed()` so trashed rows are included.
|
|
454
454
|
*/
|
|
455
455
|
static forceDestroy<T extends typeof Model>(this: T, ids: Array<string | number> | string | number): Promise<number>;
|
|
456
|
-
/**
|
|
456
|
+
/** `$this->hasMany(Related::class)`. */
|
|
457
457
|
hasMany<R extends ModelClass>(related: R, foreignKey?: string, localKey?: string): HasMany<InstanceType<R>>;
|
|
458
|
-
/**
|
|
458
|
+
/** `$this->hasOne(Related::class)`. */
|
|
459
459
|
hasOne<R extends ModelClass>(related: R, foreignKey?: string, localKey?: string): HasOne<InstanceType<R>>;
|
|
460
460
|
/**
|
|
461
|
-
*
|
|
461
|
+
* `$this->hasManyThrough(Related::class, Through::class)`.
|
|
462
462
|
* Parent → Through (firstKey) → Related (secondKey).
|
|
463
463
|
*/
|
|
464
464
|
hasManyThrough<R extends ModelClass, TThrough extends ModelClass>(related: R, through: TThrough, firstKey?: string, secondKey?: string, localKey?: string, secondLocalKey?: string): HasManyThrough<InstanceType<R>>;
|
|
465
465
|
/**
|
|
466
|
-
*
|
|
466
|
+
* `$this->hasOneThrough(Related::class, Through::class)`.
|
|
467
467
|
*/
|
|
468
468
|
hasOneThrough<R extends ModelClass, TThrough extends ModelClass>(related: R, through: TThrough, firstKey?: string, secondKey?: string, localKey?: string, secondLocalKey?: string): HasOneThrough<InstanceType<R>>;
|
|
469
|
-
/**
|
|
469
|
+
/** `$this->belongsTo(Related::class)`. */
|
|
470
470
|
belongsTo<R extends ModelClass>(related: R, foreignKey?: string, ownerKey?: string): BelongsTo<InstanceType<R>>;
|
|
471
|
-
/**
|
|
471
|
+
/** `$this->belongsToMany(Related::class, pivot)`. */
|
|
472
472
|
belongsToMany<R extends ModelClass>(related: R, table?: string, foreignPivotKey?: string, relatedPivotKey?: string): BelongsToMany<InstanceType<R>>;
|
|
473
473
|
/**
|
|
474
474
|
* Polymorphic many-to-many (`model_has_roles`-style pivots).
|
|
475
475
|
* Third argument may be the pivot table name or an options bag (tenant/legacy morph types).
|
|
476
476
|
*/
|
|
477
477
|
morphToMany<R extends ModelClass>(related: R, name: string, tableOrOptions?: string | MorphToManyOptions, foreignPivotKey?: string, relatedPivotKey?: string): MorphToMany<InstanceType<R>>;
|
|
478
|
-
/**
|
|
478
|
+
/** `$this->morphMany(Related::class, name)`. */
|
|
479
479
|
morphMany<R extends ModelClass>(related: R, name: string, type?: string, id?: string, localKey?: string): MorphMany<InstanceType<R>>;
|
|
480
|
-
/**
|
|
480
|
+
/** `$this->morphOne(Related::class, name)`. */
|
|
481
481
|
morphOne<R extends ModelClass>(related: R, name: string, type?: string, id?: string, localKey?: string): MorphOne<InstanceType<R>>;
|
|
482
|
-
/**
|
|
482
|
+
/** `$this->morphTo($name)`. */
|
|
483
483
|
morphTo(name: string, type?: string, id?: string, ownerKey?: string): MorphTo;
|
|
484
484
|
}
|
|
485
485
|
/** True when `value` is a Model subclass constructor (O(1) prototype check). */
|