@@ -44,8 +44,8 @@ export class Model {
44
44
45
45
/**
46
46
* The registry for the model. It contains predefined model schema generated
47
- * by the decorators, and gets evaluated and stored at `schema` property
48
- * when registering models to the database
47
+ * by the property decorators and gets evaluated, and stored, on the `schema`
48
+ * property when registering models to the database.
49
49
*/
50
50
protected static registries : ModelRegistries = { }
51
51
@@ -64,7 +64,7 @@ export class Model {
64
64
}
65
65
66
66
/**
67
- * Build a schema by evaluating fields and registry.
67
+ * Build the schema by evaluating fields and registry.
68
68
*/
69
69
static initializeSchema ( ) : void {
70
70
this . schemas [ this . entity ] = { }
@@ -90,43 +90,43 @@ export class Model {
90
90
}
91
91
92
92
/**
93
- * Clear the list of booted models so they will be re-booted.
93
+ * Clear the list of booted models so they can be re-booted.
94
94
*/
95
95
static clearBootedModels ( ) : void {
96
96
this . booted = { }
97
97
this . schemas = { }
98
98
}
99
99
100
100
/**
101
- * Create a new attr attribute instance.
101
+ * Create a new Attr attribute instance.
102
102
*/
103
103
static attr ( value : any ) : Attr {
104
104
return new Attr ( new this ( ) , value )
105
105
}
106
106
107
107
/**
108
- * Create a new string attribute instance.
108
+ * Create a new String attribute instance.
109
109
*/
110
110
static string ( value : string | null ) : Str {
111
111
return new Str ( new this ( ) , value )
112
112
}
113
113
114
114
/**
115
- * Create a new number attribute instance.
115
+ * Create a new Number attribute instance.
116
116
*/
117
117
static number ( value : number | null ) : Num {
118
118
return new Num ( new this ( ) , value )
119
119
}
120
120
121
121
/**
122
- * Create a new boolean attribute instance.
122
+ * Create a new Boolean attribute instance.
123
123
*/
124
124
static boolean ( value : boolean | null ) : Bool {
125
125
return new Bool ( new this ( ) , value )
126
126
}
127
127
128
128
/**
129
- * Create a new has one relation instance.
129
+ * Create a new HasOne relation instance.
130
130
*/
131
131
static hasOne (
132
132
related : typeof Model ,
@@ -141,7 +141,7 @@ export class Model {
141
141
}
142
142
143
143
/**
144
- * Create a new belongs to relation instance.
144
+ * Create a new BelongsTo relation instance.
145
145
*/
146
146
static belongsTo (
147
147
related : typeof Model ,
@@ -156,7 +156,7 @@ export class Model {
156
156
}
157
157
158
158
/**
159
- * Create a new has many relation instance.
159
+ * Create a new HasMany relation instance.
160
160
*/
161
161
static hasMany (
162
162
related : typeof Model ,
@@ -171,7 +171,7 @@ export class Model {
171
171
}
172
172
173
173
/**
174
- * Get the constructor for the model.
174
+ * Get the constructor for this model.
175
175
*/
176
176
get $self ( ) : typeof Model {
177
177
return this . constructor as typeof Model
@@ -185,14 +185,14 @@ export class Model {
185
185
}
186
186
187
187
/**
188
- * Get the entity for the model.
188
+ * Get the entity for this model.
189
189
*/
190
190
get $entity ( ) : string {
191
191
return this . $self . entity
192
192
}
193
193
194
194
/**
195
- * Get the primary key for the model.
195
+ * Get the primary key for this model.
196
196
*/
197
197
get $primaryKey ( ) : string {
198
198
return this . $self . primaryKey
@@ -208,9 +208,9 @@ export class Model {
208
208
}
209
209
210
210
/**
211
- * Create a new instance of the model. This method just provides a convenient
212
- * way for us to generate fresh model instances of this current model. It's
213
- * particularly useful during the hydration of new objects via the query .
211
+ * Create a new instance of this model. This method provides a convenient way
212
+ * to re- generate a fresh instance of this model. It's particularly useful
213
+ * during hydration through Query operations .
214
214
*/
215
215
$newInstance ( attributes ?: Element , options ?: ModelOptions ) : this {
216
216
const model = new this . $self ( attributes , options ) as this
@@ -221,14 +221,14 @@ export class Model {
221
221
}
222
222
223
223
/**
224
- * Get model fields for the model.
224
+ * Get the model fields for this model.
225
225
*/
226
226
get $fields ( ) : ModelFields {
227
227
return this . $self . schemas [ this . $entity ]
228
228
}
229
229
230
230
/**
231
- * Bootstrap the model.
231
+ * Bootstrap this model.
232
232
*/
233
233
protected $boot ( ) : void {
234
234
if ( ! this . $self . booted [ this . $entity ] ) {
@@ -239,15 +239,15 @@ export class Model {
239
239
}
240
240
241
241
/**
242
- * Build a schema by evaluating fields and registry.
242
+ * Build the schema by evaluating fields and registry.
243
243
*/
244
244
protected $initializeSchema ( ) : void {
245
245
this . $self . initializeSchema ( )
246
246
}
247
247
248
248
/**
249
- * Fill the model by the given Its default values will fill any
250
- * missing field .
249
+ * Fill this model by the given attributes. Missing fields will be populated
250
+ * by the attributes default value .
251
251
*/
252
252
$fill ( attributes : Element = { } , options : ModelOptions = { } ) : this {
253
253
const fillRelation = options . relations ?? true
@@ -267,7 +267,7 @@ export class Model {
267
267
}
268
268
269
269
/**
270
- * Fill the model filed .
270
+ * Fill the given attribute with a given value specified by the given key .
271
271
*/
272
272
protected $fillField ( key : string , attr : Attribute , value : any ) : void {
273
273
if ( value !== undefined ) {
@@ -291,7 +291,7 @@ export class Model {
291
291
}
292
292
293
293
/**
294
- * Get the index id for the model or the given record.
294
+ * Get the index id of this model or for a given record.
295
295
*/
296
296
$getIndexId ( record ?: Element ) : string {
297
297
const target = record ?? this
@@ -300,14 +300,14 @@ export class Model {
300
300
}
301
301
302
302
/**
303
- * Get the local key for the model.
303
+ * Get the local key for this model.
304
304
*/
305
305
$getLocalKey ( ) : string {
306
306
return this . $primaryKey
307
307
}
308
308
309
309
/**
310
- * Check if the model has any relations defined in the schema.
310
+ * Check if this model has any relations defined by the schema.
311
311
*/
312
312
$hasRelation ( ) : boolean {
313
313
let result = false
@@ -353,7 +353,7 @@ export class Model {
353
353
}
354
354
355
355
/**
356
- * Serialize given model POJO.
356
+ * Serialize this model, or the given model, as POJO.
357
357
*/
358
358
$toJson ( model ?: Model , options : ModelOptions = { } ) : Element {
359
359
model = model ?? this
@@ -380,7 +380,7 @@ export class Model {
380
380
}
381
381
382
382
/**
383
- * Serialize given value.
383
+ * Serialize the given value.
384
384
*/
385
385
protected serializeValue ( v : any ) : any {
386
386
if ( v === null ) {
@@ -399,14 +399,14 @@ export class Model {
399
399
}
400
400
401
401
/**
402
- * Serialize an array into json .
402
+ * Serialize the given array to JSON .
403
403
*/
404
404
protected serializeArray ( a : any [ ] ) : any [ ] {
405
405
return a . map ( ( v ) => this . serializeValue ( v ) )
406
406
}
407
407
408
408
/**
409
- * Serialize an object into json .
409
+ * Serialize the given object to JSON .
410
410
*/
411
411
protected serializeObject ( o : object ) : object {
412
412
const obj = { }
@@ -419,7 +419,7 @@ export class Model {
419
419
}
420
420
421
421
/**
422
- * Serialize given relation into json .
422
+ * Serialize the given relation to JSON .
423
423
*/
424
424
protected serializeRelation ( relation : Item ) : Element | null
425
425
protected serializeRelation ( relation : Collection ) : Element [ ]
0 commit comments