@getstrata/core 0.5.7 → 0.5.9
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/dist/entries/auth/guard.js +20 -20
- package/dist/entries/database.js +20 -20
- package/dist/entries/http/webErrorResponse.js +20 -20
- package/dist/entries/http.js +20 -20
- package/dist/entries/queue/createAppQueue.js +20 -20
- package/dist/entries/queue/publicQueue.js +20 -20
- package/dist/entries/queue/queueMetrics.js +20 -20
- package/dist/entries/view.js +20 -20
- package/dist/index.js +20 -20
- package/package.json +1 -1
|
@@ -1555,26 +1555,26 @@ class Model {
|
|
|
1555
1555
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1556
1556
|
}
|
|
1557
1557
|
static primaryKeyField() {
|
|
1558
|
-
return resolveModelRepository(
|
|
1558
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1559
1559
|
}
|
|
1560
1560
|
static hydrateAttributes(attributes) {
|
|
1561
|
-
const casts = modelStatics(
|
|
1561
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1562
1562
|
return applyCasts(attributes, casts, "hydrate");
|
|
1563
1563
|
}
|
|
1564
1564
|
static dehydrateAttributes(attributes) {
|
|
1565
|
-
const casts = modelStatics(
|
|
1565
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1566
1566
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1567
1567
|
}
|
|
1568
1568
|
static fromRecord(record, repository, exists = true) {
|
|
1569
|
-
const statics = modelStatics(
|
|
1569
|
+
const statics = modelStatics(this);
|
|
1570
1570
|
const hydrated = statics.hydrateAttributes(record);
|
|
1571
1571
|
return new statics(hydrated, repository, exists);
|
|
1572
1572
|
}
|
|
1573
1573
|
static boot() {}
|
|
1574
1574
|
static addGlobalScope(_name, scope) {
|
|
1575
|
-
ensureBooted(
|
|
1576
|
-
const existing = modelGlobalScopes.get(
|
|
1577
|
-
modelGlobalScopes.set(
|
|
1575
|
+
ensureBooted(this);
|
|
1576
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1577
|
+
modelGlobalScopes.set(this, [
|
|
1578
1578
|
...existing,
|
|
1579
1579
|
scope
|
|
1580
1580
|
]);
|
|
@@ -1584,17 +1584,17 @@ class Model {
|
|
|
1584
1584
|
}
|
|
1585
1585
|
static query() {
|
|
1586
1586
|
ensureBooted(this);
|
|
1587
|
-
const repository = resolveModelRepository(
|
|
1587
|
+
const repository = resolveModelRepository(this);
|
|
1588
1588
|
let query = repository.query();
|
|
1589
|
-
for (const scope of getGlobalScopes(
|
|
1589
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1590
1590
|
query = scope(query);
|
|
1591
1591
|
}
|
|
1592
1592
|
return query;
|
|
1593
1593
|
}
|
|
1594
1594
|
static async create(attributes) {
|
|
1595
1595
|
const statics = modelStatics(this);
|
|
1596
|
-
ensureBooted(
|
|
1597
|
-
const repository = resolveModelRepository(
|
|
1596
|
+
ensureBooted(this);
|
|
1597
|
+
const repository = resolveModelRepository(this);
|
|
1598
1598
|
const table = repository.getTable();
|
|
1599
1599
|
const timestamps = statics.$timestamps ?? true;
|
|
1600
1600
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1604,23 +1604,23 @@ class Model {
|
|
|
1604
1604
|
return statics.fromRecord(record, repository, true);
|
|
1605
1605
|
}
|
|
1606
1606
|
static async find(id) {
|
|
1607
|
-
const statics = modelStatics(
|
|
1608
|
-
const repository = resolveModelRepository(
|
|
1607
|
+
const statics = modelStatics(this);
|
|
1608
|
+
const repository = resolveModelRepository(this);
|
|
1609
1609
|
const primaryKey = repository.getTable().primaryKey;
|
|
1610
|
-
const record = await Model.query.call(
|
|
1610
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1611
1611
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1612
1612
|
}
|
|
1613
1613
|
static async findOrFail(id, errorFactory) {
|
|
1614
|
-
const model = await Model.find.call(
|
|
1614
|
+
const model = await Model.find.call(this, id);
|
|
1615
1615
|
if (model) {
|
|
1616
1616
|
return model;
|
|
1617
1617
|
}
|
|
1618
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1618
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1619
1619
|
}
|
|
1620
1620
|
static async all(options = {}) {
|
|
1621
1621
|
const statics = modelStatics(this);
|
|
1622
|
-
const repository = resolveModelRepository(
|
|
1623
|
-
let query = Model.query.call(
|
|
1622
|
+
const repository = resolveModelRepository(this);
|
|
1623
|
+
let query = Model.query.call(this);
|
|
1624
1624
|
if (options.orderBy) {
|
|
1625
1625
|
query = query.orderBy(options.orderBy);
|
|
1626
1626
|
}
|
|
@@ -1632,8 +1632,8 @@ class Model {
|
|
|
1632
1632
|
}
|
|
1633
1633
|
static async firstWhere(where, options = {}) {
|
|
1634
1634
|
const statics = modelStatics(this);
|
|
1635
|
-
const repository = resolveModelRepository(
|
|
1636
|
-
let query = Model.query.call(
|
|
1635
|
+
const repository = resolveModelRepository(this);
|
|
1636
|
+
let query = Model.query.call(this).where(where);
|
|
1637
1637
|
if (options.orderBy) {
|
|
1638
1638
|
query = query.orderBy(options.orderBy);
|
|
1639
1639
|
}
|
package/dist/entries/database.js
CHANGED
|
@@ -1353,26 +1353,26 @@ class Model {
|
|
|
1353
1353
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1354
1354
|
}
|
|
1355
1355
|
static primaryKeyField() {
|
|
1356
|
-
return resolveModelRepository(
|
|
1356
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1357
1357
|
}
|
|
1358
1358
|
static hydrateAttributes(attributes) {
|
|
1359
|
-
const casts = modelStatics(
|
|
1359
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1360
1360
|
return applyCasts(attributes, casts, "hydrate");
|
|
1361
1361
|
}
|
|
1362
1362
|
static dehydrateAttributes(attributes) {
|
|
1363
|
-
const casts = modelStatics(
|
|
1363
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1364
1364
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1365
1365
|
}
|
|
1366
1366
|
static fromRecord(record, repository, exists = true) {
|
|
1367
|
-
const statics = modelStatics(
|
|
1367
|
+
const statics = modelStatics(this);
|
|
1368
1368
|
const hydrated = statics.hydrateAttributes(record);
|
|
1369
1369
|
return new statics(hydrated, repository, exists);
|
|
1370
1370
|
}
|
|
1371
1371
|
static boot() {}
|
|
1372
1372
|
static addGlobalScope(_name, scope) {
|
|
1373
|
-
ensureBooted(
|
|
1374
|
-
const existing = modelGlobalScopes.get(
|
|
1375
|
-
modelGlobalScopes.set(
|
|
1373
|
+
ensureBooted(this);
|
|
1374
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1375
|
+
modelGlobalScopes.set(this, [
|
|
1376
1376
|
...existing,
|
|
1377
1377
|
scope
|
|
1378
1378
|
]);
|
|
@@ -1382,17 +1382,17 @@ class Model {
|
|
|
1382
1382
|
}
|
|
1383
1383
|
static query() {
|
|
1384
1384
|
ensureBooted(this);
|
|
1385
|
-
const repository = resolveModelRepository(
|
|
1385
|
+
const repository = resolveModelRepository(this);
|
|
1386
1386
|
let query = repository.query();
|
|
1387
|
-
for (const scope of getGlobalScopes(
|
|
1387
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1388
1388
|
query = scope(query);
|
|
1389
1389
|
}
|
|
1390
1390
|
return query;
|
|
1391
1391
|
}
|
|
1392
1392
|
static async create(attributes) {
|
|
1393
1393
|
const statics = modelStatics(this);
|
|
1394
|
-
ensureBooted(
|
|
1395
|
-
const repository = resolveModelRepository(
|
|
1394
|
+
ensureBooted(this);
|
|
1395
|
+
const repository = resolveModelRepository(this);
|
|
1396
1396
|
const table = repository.getTable();
|
|
1397
1397
|
const timestamps = statics.$timestamps ?? true;
|
|
1398
1398
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1402,23 +1402,23 @@ class Model {
|
|
|
1402
1402
|
return statics.fromRecord(record, repository, true);
|
|
1403
1403
|
}
|
|
1404
1404
|
static async find(id) {
|
|
1405
|
-
const statics = modelStatics(
|
|
1406
|
-
const repository = resolveModelRepository(
|
|
1405
|
+
const statics = modelStatics(this);
|
|
1406
|
+
const repository = resolveModelRepository(this);
|
|
1407
1407
|
const primaryKey = repository.getTable().primaryKey;
|
|
1408
|
-
const record = await Model.query.call(
|
|
1408
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1409
1409
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1410
1410
|
}
|
|
1411
1411
|
static async findOrFail(id, errorFactory) {
|
|
1412
|
-
const model = await Model.find.call(
|
|
1412
|
+
const model = await Model.find.call(this, id);
|
|
1413
1413
|
if (model) {
|
|
1414
1414
|
return model;
|
|
1415
1415
|
}
|
|
1416
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1416
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1417
1417
|
}
|
|
1418
1418
|
static async all(options = {}) {
|
|
1419
1419
|
const statics = modelStatics(this);
|
|
1420
|
-
const repository = resolveModelRepository(
|
|
1421
|
-
let query = Model.query.call(
|
|
1420
|
+
const repository = resolveModelRepository(this);
|
|
1421
|
+
let query = Model.query.call(this);
|
|
1422
1422
|
if (options.orderBy) {
|
|
1423
1423
|
query = query.orderBy(options.orderBy);
|
|
1424
1424
|
}
|
|
@@ -1430,8 +1430,8 @@ class Model {
|
|
|
1430
1430
|
}
|
|
1431
1431
|
static async firstWhere(where, options = {}) {
|
|
1432
1432
|
const statics = modelStatics(this);
|
|
1433
|
-
const repository = resolveModelRepository(
|
|
1434
|
-
let query = Model.query.call(
|
|
1433
|
+
const repository = resolveModelRepository(this);
|
|
1434
|
+
let query = Model.query.call(this).where(where);
|
|
1435
1435
|
if (options.orderBy) {
|
|
1436
1436
|
query = query.orderBy(options.orderBy);
|
|
1437
1437
|
}
|
|
@@ -1577,26 +1577,26 @@ class Model {
|
|
|
1577
1577
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1578
1578
|
}
|
|
1579
1579
|
static primaryKeyField() {
|
|
1580
|
-
return resolveModelRepository(
|
|
1580
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1581
1581
|
}
|
|
1582
1582
|
static hydrateAttributes(attributes) {
|
|
1583
|
-
const casts = modelStatics(
|
|
1583
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1584
1584
|
return applyCasts(attributes, casts, "hydrate");
|
|
1585
1585
|
}
|
|
1586
1586
|
static dehydrateAttributes(attributes) {
|
|
1587
|
-
const casts = modelStatics(
|
|
1587
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1588
1588
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1589
1589
|
}
|
|
1590
1590
|
static fromRecord(record, repository, exists = true) {
|
|
1591
|
-
const statics = modelStatics(
|
|
1591
|
+
const statics = modelStatics(this);
|
|
1592
1592
|
const hydrated = statics.hydrateAttributes(record);
|
|
1593
1593
|
return new statics(hydrated, repository, exists);
|
|
1594
1594
|
}
|
|
1595
1595
|
static boot() {}
|
|
1596
1596
|
static addGlobalScope(_name, scope) {
|
|
1597
|
-
ensureBooted(
|
|
1598
|
-
const existing = modelGlobalScopes.get(
|
|
1599
|
-
modelGlobalScopes.set(
|
|
1597
|
+
ensureBooted(this);
|
|
1598
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1599
|
+
modelGlobalScopes.set(this, [
|
|
1600
1600
|
...existing,
|
|
1601
1601
|
scope
|
|
1602
1602
|
]);
|
|
@@ -1606,17 +1606,17 @@ class Model {
|
|
|
1606
1606
|
}
|
|
1607
1607
|
static query() {
|
|
1608
1608
|
ensureBooted(this);
|
|
1609
|
-
const repository = resolveModelRepository(
|
|
1609
|
+
const repository = resolveModelRepository(this);
|
|
1610
1610
|
let query = repository.query();
|
|
1611
|
-
for (const scope of getGlobalScopes(
|
|
1611
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1612
1612
|
query = scope(query);
|
|
1613
1613
|
}
|
|
1614
1614
|
return query;
|
|
1615
1615
|
}
|
|
1616
1616
|
static async create(attributes) {
|
|
1617
1617
|
const statics = modelStatics(this);
|
|
1618
|
-
ensureBooted(
|
|
1619
|
-
const repository = resolveModelRepository(
|
|
1618
|
+
ensureBooted(this);
|
|
1619
|
+
const repository = resolveModelRepository(this);
|
|
1620
1620
|
const table = repository.getTable();
|
|
1621
1621
|
const timestamps = statics.$timestamps ?? true;
|
|
1622
1622
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1626,23 +1626,23 @@ class Model {
|
|
|
1626
1626
|
return statics.fromRecord(record, repository, true);
|
|
1627
1627
|
}
|
|
1628
1628
|
static async find(id) {
|
|
1629
|
-
const statics = modelStatics(
|
|
1630
|
-
const repository = resolveModelRepository(
|
|
1629
|
+
const statics = modelStatics(this);
|
|
1630
|
+
const repository = resolveModelRepository(this);
|
|
1631
1631
|
const primaryKey = repository.getTable().primaryKey;
|
|
1632
|
-
const record = await Model.query.call(
|
|
1632
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1633
1633
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1634
1634
|
}
|
|
1635
1635
|
static async findOrFail(id, errorFactory) {
|
|
1636
|
-
const model = await Model.find.call(
|
|
1636
|
+
const model = await Model.find.call(this, id);
|
|
1637
1637
|
if (model) {
|
|
1638
1638
|
return model;
|
|
1639
1639
|
}
|
|
1640
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1640
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1641
1641
|
}
|
|
1642
1642
|
static async all(options = {}) {
|
|
1643
1643
|
const statics = modelStatics(this);
|
|
1644
|
-
const repository = resolveModelRepository(
|
|
1645
|
-
let query = Model.query.call(
|
|
1644
|
+
const repository = resolveModelRepository(this);
|
|
1645
|
+
let query = Model.query.call(this);
|
|
1646
1646
|
if (options.orderBy) {
|
|
1647
1647
|
query = query.orderBy(options.orderBy);
|
|
1648
1648
|
}
|
|
@@ -1654,8 +1654,8 @@ class Model {
|
|
|
1654
1654
|
}
|
|
1655
1655
|
static async firstWhere(where, options = {}) {
|
|
1656
1656
|
const statics = modelStatics(this);
|
|
1657
|
-
const repository = resolveModelRepository(
|
|
1658
|
-
let query = Model.query.call(
|
|
1657
|
+
const repository = resolveModelRepository(this);
|
|
1658
|
+
let query = Model.query.call(this).where(where);
|
|
1659
1659
|
if (options.orderBy) {
|
|
1660
1660
|
query = query.orderBy(options.orderBy);
|
|
1661
1661
|
}
|
package/dist/entries/http.js
CHANGED
|
@@ -1577,26 +1577,26 @@ class Model {
|
|
|
1577
1577
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1578
1578
|
}
|
|
1579
1579
|
static primaryKeyField() {
|
|
1580
|
-
return resolveModelRepository(
|
|
1580
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1581
1581
|
}
|
|
1582
1582
|
static hydrateAttributes(attributes) {
|
|
1583
|
-
const casts = modelStatics(
|
|
1583
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1584
1584
|
return applyCasts(attributes, casts, "hydrate");
|
|
1585
1585
|
}
|
|
1586
1586
|
static dehydrateAttributes(attributes) {
|
|
1587
|
-
const casts = modelStatics(
|
|
1587
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1588
1588
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1589
1589
|
}
|
|
1590
1590
|
static fromRecord(record, repository, exists = true) {
|
|
1591
|
-
const statics = modelStatics(
|
|
1591
|
+
const statics = modelStatics(this);
|
|
1592
1592
|
const hydrated = statics.hydrateAttributes(record);
|
|
1593
1593
|
return new statics(hydrated, repository, exists);
|
|
1594
1594
|
}
|
|
1595
1595
|
static boot() {}
|
|
1596
1596
|
static addGlobalScope(_name, scope) {
|
|
1597
|
-
ensureBooted(
|
|
1598
|
-
const existing = modelGlobalScopes.get(
|
|
1599
|
-
modelGlobalScopes.set(
|
|
1597
|
+
ensureBooted(this);
|
|
1598
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1599
|
+
modelGlobalScopes.set(this, [
|
|
1600
1600
|
...existing,
|
|
1601
1601
|
scope
|
|
1602
1602
|
]);
|
|
@@ -1606,17 +1606,17 @@ class Model {
|
|
|
1606
1606
|
}
|
|
1607
1607
|
static query() {
|
|
1608
1608
|
ensureBooted(this);
|
|
1609
|
-
const repository = resolveModelRepository(
|
|
1609
|
+
const repository = resolveModelRepository(this);
|
|
1610
1610
|
let query = repository.query();
|
|
1611
|
-
for (const scope of getGlobalScopes(
|
|
1611
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1612
1612
|
query = scope(query);
|
|
1613
1613
|
}
|
|
1614
1614
|
return query;
|
|
1615
1615
|
}
|
|
1616
1616
|
static async create(attributes) {
|
|
1617
1617
|
const statics = modelStatics(this);
|
|
1618
|
-
ensureBooted(
|
|
1619
|
-
const repository = resolveModelRepository(
|
|
1618
|
+
ensureBooted(this);
|
|
1619
|
+
const repository = resolveModelRepository(this);
|
|
1620
1620
|
const table = repository.getTable();
|
|
1621
1621
|
const timestamps = statics.$timestamps ?? true;
|
|
1622
1622
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1626,23 +1626,23 @@ class Model {
|
|
|
1626
1626
|
return statics.fromRecord(record, repository, true);
|
|
1627
1627
|
}
|
|
1628
1628
|
static async find(id) {
|
|
1629
|
-
const statics = modelStatics(
|
|
1630
|
-
const repository = resolveModelRepository(
|
|
1629
|
+
const statics = modelStatics(this);
|
|
1630
|
+
const repository = resolveModelRepository(this);
|
|
1631
1631
|
const primaryKey = repository.getTable().primaryKey;
|
|
1632
|
-
const record = await Model.query.call(
|
|
1632
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1633
1633
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1634
1634
|
}
|
|
1635
1635
|
static async findOrFail(id, errorFactory) {
|
|
1636
|
-
const model = await Model.find.call(
|
|
1636
|
+
const model = await Model.find.call(this, id);
|
|
1637
1637
|
if (model) {
|
|
1638
1638
|
return model;
|
|
1639
1639
|
}
|
|
1640
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1640
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1641
1641
|
}
|
|
1642
1642
|
static async all(options = {}) {
|
|
1643
1643
|
const statics = modelStatics(this);
|
|
1644
|
-
const repository = resolveModelRepository(
|
|
1645
|
-
let query = Model.query.call(
|
|
1644
|
+
const repository = resolveModelRepository(this);
|
|
1645
|
+
let query = Model.query.call(this);
|
|
1646
1646
|
if (options.orderBy) {
|
|
1647
1647
|
query = query.orderBy(options.orderBy);
|
|
1648
1648
|
}
|
|
@@ -1654,8 +1654,8 @@ class Model {
|
|
|
1654
1654
|
}
|
|
1655
1655
|
static async firstWhere(where, options = {}) {
|
|
1656
1656
|
const statics = modelStatics(this);
|
|
1657
|
-
const repository = resolveModelRepository(
|
|
1658
|
-
let query = Model.query.call(
|
|
1657
|
+
const repository = resolveModelRepository(this);
|
|
1658
|
+
let query = Model.query.call(this).where(where);
|
|
1659
1659
|
if (options.orderBy) {
|
|
1660
1660
|
query = query.orderBy(options.orderBy);
|
|
1661
1661
|
}
|
|
@@ -1751,26 +1751,26 @@ class Model {
|
|
|
1751
1751
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1752
1752
|
}
|
|
1753
1753
|
static primaryKeyField() {
|
|
1754
|
-
return resolveModelRepository(
|
|
1754
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1755
1755
|
}
|
|
1756
1756
|
static hydrateAttributes(attributes) {
|
|
1757
|
-
const casts = modelStatics(
|
|
1757
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1758
1758
|
return applyCasts(attributes, casts, "hydrate");
|
|
1759
1759
|
}
|
|
1760
1760
|
static dehydrateAttributes(attributes) {
|
|
1761
|
-
const casts = modelStatics(
|
|
1761
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1762
1762
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1763
1763
|
}
|
|
1764
1764
|
static fromRecord(record, repository, exists = true) {
|
|
1765
|
-
const statics = modelStatics(
|
|
1765
|
+
const statics = modelStatics(this);
|
|
1766
1766
|
const hydrated = statics.hydrateAttributes(record);
|
|
1767
1767
|
return new statics(hydrated, repository, exists);
|
|
1768
1768
|
}
|
|
1769
1769
|
static boot() {}
|
|
1770
1770
|
static addGlobalScope(_name, scope) {
|
|
1771
|
-
ensureBooted(
|
|
1772
|
-
const existing = modelGlobalScopes.get(
|
|
1773
|
-
modelGlobalScopes.set(
|
|
1771
|
+
ensureBooted(this);
|
|
1772
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1773
|
+
modelGlobalScopes.set(this, [
|
|
1774
1774
|
...existing,
|
|
1775
1775
|
scope
|
|
1776
1776
|
]);
|
|
@@ -1780,17 +1780,17 @@ class Model {
|
|
|
1780
1780
|
}
|
|
1781
1781
|
static query() {
|
|
1782
1782
|
ensureBooted(this);
|
|
1783
|
-
const repository = resolveModelRepository(
|
|
1783
|
+
const repository = resolveModelRepository(this);
|
|
1784
1784
|
let query = repository.query();
|
|
1785
|
-
for (const scope of getGlobalScopes(
|
|
1785
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1786
1786
|
query = scope(query);
|
|
1787
1787
|
}
|
|
1788
1788
|
return query;
|
|
1789
1789
|
}
|
|
1790
1790
|
static async create(attributes) {
|
|
1791
1791
|
const statics = modelStatics(this);
|
|
1792
|
-
ensureBooted(
|
|
1793
|
-
const repository = resolveModelRepository(
|
|
1792
|
+
ensureBooted(this);
|
|
1793
|
+
const repository = resolveModelRepository(this);
|
|
1794
1794
|
const table = repository.getTable();
|
|
1795
1795
|
const timestamps = statics.$timestamps ?? true;
|
|
1796
1796
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1800,23 +1800,23 @@ class Model {
|
|
|
1800
1800
|
return statics.fromRecord(record, repository, true);
|
|
1801
1801
|
}
|
|
1802
1802
|
static async find(id) {
|
|
1803
|
-
const statics = modelStatics(
|
|
1804
|
-
const repository = resolveModelRepository(
|
|
1803
|
+
const statics = modelStatics(this);
|
|
1804
|
+
const repository = resolveModelRepository(this);
|
|
1805
1805
|
const primaryKey = repository.getTable().primaryKey;
|
|
1806
|
-
const record = await Model.query.call(
|
|
1806
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1807
1807
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1808
1808
|
}
|
|
1809
1809
|
static async findOrFail(id, errorFactory) {
|
|
1810
|
-
const model = await Model.find.call(
|
|
1810
|
+
const model = await Model.find.call(this, id);
|
|
1811
1811
|
if (model) {
|
|
1812
1812
|
return model;
|
|
1813
1813
|
}
|
|
1814
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1814
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1815
1815
|
}
|
|
1816
1816
|
static async all(options = {}) {
|
|
1817
1817
|
const statics = modelStatics(this);
|
|
1818
|
-
const repository = resolveModelRepository(
|
|
1819
|
-
let query = Model.query.call(
|
|
1818
|
+
const repository = resolveModelRepository(this);
|
|
1819
|
+
let query = Model.query.call(this);
|
|
1820
1820
|
if (options.orderBy) {
|
|
1821
1821
|
query = query.orderBy(options.orderBy);
|
|
1822
1822
|
}
|
|
@@ -1828,8 +1828,8 @@ class Model {
|
|
|
1828
1828
|
}
|
|
1829
1829
|
static async firstWhere(where, options = {}) {
|
|
1830
1830
|
const statics = modelStatics(this);
|
|
1831
|
-
const repository = resolveModelRepository(
|
|
1832
|
-
let query = Model.query.call(
|
|
1831
|
+
const repository = resolveModelRepository(this);
|
|
1832
|
+
let query = Model.query.call(this).where(where);
|
|
1833
1833
|
if (options.orderBy) {
|
|
1834
1834
|
query = query.orderBy(options.orderBy);
|
|
1835
1835
|
}
|
|
@@ -1353,26 +1353,26 @@ class Model {
|
|
|
1353
1353
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1354
1354
|
}
|
|
1355
1355
|
static primaryKeyField() {
|
|
1356
|
-
return resolveModelRepository(
|
|
1356
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1357
1357
|
}
|
|
1358
1358
|
static hydrateAttributes(attributes) {
|
|
1359
|
-
const casts = modelStatics(
|
|
1359
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1360
1360
|
return applyCasts(attributes, casts, "hydrate");
|
|
1361
1361
|
}
|
|
1362
1362
|
static dehydrateAttributes(attributes) {
|
|
1363
|
-
const casts = modelStatics(
|
|
1363
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1364
1364
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1365
1365
|
}
|
|
1366
1366
|
static fromRecord(record, repository, exists = true) {
|
|
1367
|
-
const statics = modelStatics(
|
|
1367
|
+
const statics = modelStatics(this);
|
|
1368
1368
|
const hydrated = statics.hydrateAttributes(record);
|
|
1369
1369
|
return new statics(hydrated, repository, exists);
|
|
1370
1370
|
}
|
|
1371
1371
|
static boot() {}
|
|
1372
1372
|
static addGlobalScope(_name, scope) {
|
|
1373
|
-
ensureBooted(
|
|
1374
|
-
const existing = modelGlobalScopes.get(
|
|
1375
|
-
modelGlobalScopes.set(
|
|
1373
|
+
ensureBooted(this);
|
|
1374
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1375
|
+
modelGlobalScopes.set(this, [
|
|
1376
1376
|
...existing,
|
|
1377
1377
|
scope
|
|
1378
1378
|
]);
|
|
@@ -1382,17 +1382,17 @@ class Model {
|
|
|
1382
1382
|
}
|
|
1383
1383
|
static query() {
|
|
1384
1384
|
ensureBooted(this);
|
|
1385
|
-
const repository = resolveModelRepository(
|
|
1385
|
+
const repository = resolveModelRepository(this);
|
|
1386
1386
|
let query = repository.query();
|
|
1387
|
-
for (const scope of getGlobalScopes(
|
|
1387
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1388
1388
|
query = scope(query);
|
|
1389
1389
|
}
|
|
1390
1390
|
return query;
|
|
1391
1391
|
}
|
|
1392
1392
|
static async create(attributes) {
|
|
1393
1393
|
const statics = modelStatics(this);
|
|
1394
|
-
ensureBooted(
|
|
1395
|
-
const repository = resolveModelRepository(
|
|
1394
|
+
ensureBooted(this);
|
|
1395
|
+
const repository = resolveModelRepository(this);
|
|
1396
1396
|
const table = repository.getTable();
|
|
1397
1397
|
const timestamps = statics.$timestamps ?? true;
|
|
1398
1398
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1402,23 +1402,23 @@ class Model {
|
|
|
1402
1402
|
return statics.fromRecord(record, repository, true);
|
|
1403
1403
|
}
|
|
1404
1404
|
static async find(id) {
|
|
1405
|
-
const statics = modelStatics(
|
|
1406
|
-
const repository = resolveModelRepository(
|
|
1405
|
+
const statics = modelStatics(this);
|
|
1406
|
+
const repository = resolveModelRepository(this);
|
|
1407
1407
|
const primaryKey = repository.getTable().primaryKey;
|
|
1408
|
-
const record = await Model.query.call(
|
|
1408
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1409
1409
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1410
1410
|
}
|
|
1411
1411
|
static async findOrFail(id, errorFactory) {
|
|
1412
|
-
const model = await Model.find.call(
|
|
1412
|
+
const model = await Model.find.call(this, id);
|
|
1413
1413
|
if (model) {
|
|
1414
1414
|
return model;
|
|
1415
1415
|
}
|
|
1416
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1416
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1417
1417
|
}
|
|
1418
1418
|
static async all(options = {}) {
|
|
1419
1419
|
const statics = modelStatics(this);
|
|
1420
|
-
const repository = resolveModelRepository(
|
|
1421
|
-
let query = Model.query.call(
|
|
1420
|
+
const repository = resolveModelRepository(this);
|
|
1421
|
+
let query = Model.query.call(this);
|
|
1422
1422
|
if (options.orderBy) {
|
|
1423
1423
|
query = query.orderBy(options.orderBy);
|
|
1424
1424
|
}
|
|
@@ -1430,8 +1430,8 @@ class Model {
|
|
|
1430
1430
|
}
|
|
1431
1431
|
static async firstWhere(where, options = {}) {
|
|
1432
1432
|
const statics = modelStatics(this);
|
|
1433
|
-
const repository = resolveModelRepository(
|
|
1434
|
-
let query = Model.query.call(
|
|
1433
|
+
const repository = resolveModelRepository(this);
|
|
1434
|
+
let query = Model.query.call(this).where(where);
|
|
1435
1435
|
if (options.orderBy) {
|
|
1436
1436
|
query = query.orderBy(options.orderBy);
|
|
1437
1437
|
}
|
|
@@ -1761,26 +1761,26 @@ class Model {
|
|
|
1761
1761
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1762
1762
|
}
|
|
1763
1763
|
static primaryKeyField() {
|
|
1764
|
-
return resolveModelRepository(
|
|
1764
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1765
1765
|
}
|
|
1766
1766
|
static hydrateAttributes(attributes) {
|
|
1767
|
-
const casts = modelStatics(
|
|
1767
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1768
1768
|
return applyCasts(attributes, casts, "hydrate");
|
|
1769
1769
|
}
|
|
1770
1770
|
static dehydrateAttributes(attributes) {
|
|
1771
|
-
const casts = modelStatics(
|
|
1771
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1772
1772
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1773
1773
|
}
|
|
1774
1774
|
static fromRecord(record, repository, exists = true) {
|
|
1775
|
-
const statics = modelStatics(
|
|
1775
|
+
const statics = modelStatics(this);
|
|
1776
1776
|
const hydrated = statics.hydrateAttributes(record);
|
|
1777
1777
|
return new statics(hydrated, repository, exists);
|
|
1778
1778
|
}
|
|
1779
1779
|
static boot() {}
|
|
1780
1780
|
static addGlobalScope(_name, scope) {
|
|
1781
|
-
ensureBooted(
|
|
1782
|
-
const existing = modelGlobalScopes.get(
|
|
1783
|
-
modelGlobalScopes.set(
|
|
1781
|
+
ensureBooted(this);
|
|
1782
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1783
|
+
modelGlobalScopes.set(this, [
|
|
1784
1784
|
...existing,
|
|
1785
1785
|
scope
|
|
1786
1786
|
]);
|
|
@@ -1790,17 +1790,17 @@ class Model {
|
|
|
1790
1790
|
}
|
|
1791
1791
|
static query() {
|
|
1792
1792
|
ensureBooted(this);
|
|
1793
|
-
const repository = resolveModelRepository(
|
|
1793
|
+
const repository = resolveModelRepository(this);
|
|
1794
1794
|
let query = repository.query();
|
|
1795
|
-
for (const scope of getGlobalScopes(
|
|
1795
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1796
1796
|
query = scope(query);
|
|
1797
1797
|
}
|
|
1798
1798
|
return query;
|
|
1799
1799
|
}
|
|
1800
1800
|
static async create(attributes) {
|
|
1801
1801
|
const statics = modelStatics(this);
|
|
1802
|
-
ensureBooted(
|
|
1803
|
-
const repository = resolveModelRepository(
|
|
1802
|
+
ensureBooted(this);
|
|
1803
|
+
const repository = resolveModelRepository(this);
|
|
1804
1804
|
const table = repository.getTable();
|
|
1805
1805
|
const timestamps = statics.$timestamps ?? true;
|
|
1806
1806
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1810,23 +1810,23 @@ class Model {
|
|
|
1810
1810
|
return statics.fromRecord(record, repository, true);
|
|
1811
1811
|
}
|
|
1812
1812
|
static async find(id) {
|
|
1813
|
-
const statics = modelStatics(
|
|
1814
|
-
const repository = resolveModelRepository(
|
|
1813
|
+
const statics = modelStatics(this);
|
|
1814
|
+
const repository = resolveModelRepository(this);
|
|
1815
1815
|
const primaryKey = repository.getTable().primaryKey;
|
|
1816
|
-
const record = await Model.query.call(
|
|
1816
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1817
1817
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1818
1818
|
}
|
|
1819
1819
|
static async findOrFail(id, errorFactory) {
|
|
1820
|
-
const model = await Model.find.call(
|
|
1820
|
+
const model = await Model.find.call(this, id);
|
|
1821
1821
|
if (model) {
|
|
1822
1822
|
return model;
|
|
1823
1823
|
}
|
|
1824
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1824
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1825
1825
|
}
|
|
1826
1826
|
static async all(options = {}) {
|
|
1827
1827
|
const statics = modelStatics(this);
|
|
1828
|
-
const repository = resolveModelRepository(
|
|
1829
|
-
let query = Model.query.call(
|
|
1828
|
+
const repository = resolveModelRepository(this);
|
|
1829
|
+
let query = Model.query.call(this);
|
|
1830
1830
|
if (options.orderBy) {
|
|
1831
1831
|
query = query.orderBy(options.orderBy);
|
|
1832
1832
|
}
|
|
@@ -1838,8 +1838,8 @@ class Model {
|
|
|
1838
1838
|
}
|
|
1839
1839
|
static async firstWhere(where, options = {}) {
|
|
1840
1840
|
const statics = modelStatics(this);
|
|
1841
|
-
const repository = resolveModelRepository(
|
|
1842
|
-
let query = Model.query.call(
|
|
1841
|
+
const repository = resolveModelRepository(this);
|
|
1842
|
+
let query = Model.query.call(this).where(where);
|
|
1843
1843
|
if (options.orderBy) {
|
|
1844
1844
|
query = query.orderBy(options.orderBy);
|
|
1845
1845
|
}
|
package/dist/entries/view.js
CHANGED
|
@@ -1562,26 +1562,26 @@ class Model {
|
|
|
1562
1562
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1563
1563
|
}
|
|
1564
1564
|
static primaryKeyField() {
|
|
1565
|
-
return resolveModelRepository(
|
|
1565
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1566
1566
|
}
|
|
1567
1567
|
static hydrateAttributes(attributes) {
|
|
1568
|
-
const casts = modelStatics(
|
|
1568
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1569
1569
|
return applyCasts(attributes, casts, "hydrate");
|
|
1570
1570
|
}
|
|
1571
1571
|
static dehydrateAttributes(attributes) {
|
|
1572
|
-
const casts = modelStatics(
|
|
1572
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1573
1573
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1574
1574
|
}
|
|
1575
1575
|
static fromRecord(record, repository, exists = true) {
|
|
1576
|
-
const statics = modelStatics(
|
|
1576
|
+
const statics = modelStatics(this);
|
|
1577
1577
|
const hydrated = statics.hydrateAttributes(record);
|
|
1578
1578
|
return new statics(hydrated, repository, exists);
|
|
1579
1579
|
}
|
|
1580
1580
|
static boot() {}
|
|
1581
1581
|
static addGlobalScope(_name, scope) {
|
|
1582
|
-
ensureBooted(
|
|
1583
|
-
const existing = modelGlobalScopes.get(
|
|
1584
|
-
modelGlobalScopes.set(
|
|
1582
|
+
ensureBooted(this);
|
|
1583
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1584
|
+
modelGlobalScopes.set(this, [
|
|
1585
1585
|
...existing,
|
|
1586
1586
|
scope
|
|
1587
1587
|
]);
|
|
@@ -1591,17 +1591,17 @@ class Model {
|
|
|
1591
1591
|
}
|
|
1592
1592
|
static query() {
|
|
1593
1593
|
ensureBooted(this);
|
|
1594
|
-
const repository = resolveModelRepository(
|
|
1594
|
+
const repository = resolveModelRepository(this);
|
|
1595
1595
|
let query = repository.query();
|
|
1596
|
-
for (const scope of getGlobalScopes(
|
|
1596
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1597
1597
|
query = scope(query);
|
|
1598
1598
|
}
|
|
1599
1599
|
return query;
|
|
1600
1600
|
}
|
|
1601
1601
|
static async create(attributes) {
|
|
1602
1602
|
const statics = modelStatics(this);
|
|
1603
|
-
ensureBooted(
|
|
1604
|
-
const repository = resolveModelRepository(
|
|
1603
|
+
ensureBooted(this);
|
|
1604
|
+
const repository = resolveModelRepository(this);
|
|
1605
1605
|
const table = repository.getTable();
|
|
1606
1606
|
const timestamps = statics.$timestamps ?? true;
|
|
1607
1607
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1611,23 +1611,23 @@ class Model {
|
|
|
1611
1611
|
return statics.fromRecord(record, repository, true);
|
|
1612
1612
|
}
|
|
1613
1613
|
static async find(id) {
|
|
1614
|
-
const statics = modelStatics(
|
|
1615
|
-
const repository = resolveModelRepository(
|
|
1614
|
+
const statics = modelStatics(this);
|
|
1615
|
+
const repository = resolveModelRepository(this);
|
|
1616
1616
|
const primaryKey = repository.getTable().primaryKey;
|
|
1617
|
-
const record = await Model.query.call(
|
|
1617
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1618
1618
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1619
1619
|
}
|
|
1620
1620
|
static async findOrFail(id, errorFactory) {
|
|
1621
|
-
const model = await Model.find.call(
|
|
1621
|
+
const model = await Model.find.call(this, id);
|
|
1622
1622
|
if (model) {
|
|
1623
1623
|
return model;
|
|
1624
1624
|
}
|
|
1625
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1625
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1626
1626
|
}
|
|
1627
1627
|
static async all(options = {}) {
|
|
1628
1628
|
const statics = modelStatics(this);
|
|
1629
|
-
const repository = resolveModelRepository(
|
|
1630
|
-
let query = Model.query.call(
|
|
1629
|
+
const repository = resolveModelRepository(this);
|
|
1630
|
+
let query = Model.query.call(this);
|
|
1631
1631
|
if (options.orderBy) {
|
|
1632
1632
|
query = query.orderBy(options.orderBy);
|
|
1633
1633
|
}
|
|
@@ -1639,8 +1639,8 @@ class Model {
|
|
|
1639
1639
|
}
|
|
1640
1640
|
static async firstWhere(where, options = {}) {
|
|
1641
1641
|
const statics = modelStatics(this);
|
|
1642
|
-
const repository = resolveModelRepository(
|
|
1643
|
-
let query = Model.query.call(
|
|
1642
|
+
const repository = resolveModelRepository(this);
|
|
1643
|
+
let query = Model.query.call(this).where(where);
|
|
1644
1644
|
if (options.orderBy) {
|
|
1645
1645
|
query = query.orderBy(options.orderBy);
|
|
1646
1646
|
}
|
package/dist/index.js
CHANGED
|
@@ -1747,26 +1747,26 @@ class Model {
|
|
|
1747
1747
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1748
1748
|
}
|
|
1749
1749
|
static primaryKeyField() {
|
|
1750
|
-
return resolveModelRepository(
|
|
1750
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1751
1751
|
}
|
|
1752
1752
|
static hydrateAttributes(attributes) {
|
|
1753
|
-
const casts = modelStatics(
|
|
1753
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1754
1754
|
return applyCasts(attributes, casts, "hydrate");
|
|
1755
1755
|
}
|
|
1756
1756
|
static dehydrateAttributes(attributes) {
|
|
1757
|
-
const casts = modelStatics(
|
|
1757
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1758
1758
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1759
1759
|
}
|
|
1760
1760
|
static fromRecord(record, repository, exists = true) {
|
|
1761
|
-
const statics = modelStatics(
|
|
1761
|
+
const statics = modelStatics(this);
|
|
1762
1762
|
const hydrated = statics.hydrateAttributes(record);
|
|
1763
1763
|
return new statics(hydrated, repository, exists);
|
|
1764
1764
|
}
|
|
1765
1765
|
static boot() {}
|
|
1766
1766
|
static addGlobalScope(_name, scope) {
|
|
1767
|
-
ensureBooted(
|
|
1768
|
-
const existing = modelGlobalScopes.get(
|
|
1769
|
-
modelGlobalScopes.set(
|
|
1767
|
+
ensureBooted(this);
|
|
1768
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1769
|
+
modelGlobalScopes.set(this, [
|
|
1770
1770
|
...existing,
|
|
1771
1771
|
scope
|
|
1772
1772
|
]);
|
|
@@ -1776,17 +1776,17 @@ class Model {
|
|
|
1776
1776
|
}
|
|
1777
1777
|
static query() {
|
|
1778
1778
|
ensureBooted(this);
|
|
1779
|
-
const repository = resolveModelRepository(
|
|
1779
|
+
const repository = resolveModelRepository(this);
|
|
1780
1780
|
let query = repository.query();
|
|
1781
|
-
for (const scope of getGlobalScopes(
|
|
1781
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1782
1782
|
query = scope(query);
|
|
1783
1783
|
}
|
|
1784
1784
|
return query;
|
|
1785
1785
|
}
|
|
1786
1786
|
static async create(attributes) {
|
|
1787
1787
|
const statics = modelStatics(this);
|
|
1788
|
-
ensureBooted(
|
|
1789
|
-
const repository = resolveModelRepository(
|
|
1788
|
+
ensureBooted(this);
|
|
1789
|
+
const repository = resolveModelRepository(this);
|
|
1790
1790
|
const table = repository.getTable();
|
|
1791
1791
|
const timestamps = statics.$timestamps ?? true;
|
|
1792
1792
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1796,23 +1796,23 @@ class Model {
|
|
|
1796
1796
|
return statics.fromRecord(record, repository, true);
|
|
1797
1797
|
}
|
|
1798
1798
|
static async find(id) {
|
|
1799
|
-
const statics = modelStatics(
|
|
1800
|
-
const repository = resolveModelRepository(
|
|
1799
|
+
const statics = modelStatics(this);
|
|
1800
|
+
const repository = resolveModelRepository(this);
|
|
1801
1801
|
const primaryKey = repository.getTable().primaryKey;
|
|
1802
|
-
const record = await Model.query.call(
|
|
1802
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1803
1803
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1804
1804
|
}
|
|
1805
1805
|
static async findOrFail(id, errorFactory) {
|
|
1806
|
-
const model = await Model.find.call(
|
|
1806
|
+
const model = await Model.find.call(this, id);
|
|
1807
1807
|
if (model) {
|
|
1808
1808
|
return model;
|
|
1809
1809
|
}
|
|
1810
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1810
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1811
1811
|
}
|
|
1812
1812
|
static async all(options = {}) {
|
|
1813
1813
|
const statics = modelStatics(this);
|
|
1814
|
-
const repository = resolveModelRepository(
|
|
1815
|
-
let query = Model.query.call(
|
|
1814
|
+
const repository = resolveModelRepository(this);
|
|
1815
|
+
let query = Model.query.call(this);
|
|
1816
1816
|
if (options.orderBy) {
|
|
1817
1817
|
query = query.orderBy(options.orderBy);
|
|
1818
1818
|
}
|
|
@@ -1824,8 +1824,8 @@ class Model {
|
|
|
1824
1824
|
}
|
|
1825
1825
|
static async firstWhere(where, options = {}) {
|
|
1826
1826
|
const statics = modelStatics(this);
|
|
1827
|
-
const repository = resolveModelRepository(
|
|
1828
|
-
let query = Model.query.call(
|
|
1827
|
+
const repository = resolveModelRepository(this);
|
|
1828
|
+
let query = Model.query.call(this).where(where);
|
|
1829
1829
|
if (options.orderBy) {
|
|
1830
1830
|
query = query.orderBy(options.orderBy);
|
|
1831
1831
|
}
|