@getstrata/core 0.5.1 → 0.5.3
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
|
@@ -1557,26 +1557,26 @@ class Model {
|
|
|
1557
1557
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1558
1558
|
}
|
|
1559
1559
|
static primaryKeyField() {
|
|
1560
|
-
return resolveModelRepository(
|
|
1560
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1561
1561
|
}
|
|
1562
1562
|
static hydrateAttributes(attributes) {
|
|
1563
|
-
const casts = modelStatics(
|
|
1563
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1564
1564
|
return applyCasts(attributes, casts, "hydrate");
|
|
1565
1565
|
}
|
|
1566
1566
|
static dehydrateAttributes(attributes) {
|
|
1567
|
-
const casts = modelStatics(
|
|
1567
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1568
1568
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1569
1569
|
}
|
|
1570
1570
|
static fromRecord(record, repository, exists = true) {
|
|
1571
|
-
const statics = modelStatics(
|
|
1571
|
+
const statics = modelStatics(this);
|
|
1572
1572
|
const hydrated = statics.hydrateAttributes(record);
|
|
1573
1573
|
return new statics(hydrated, repository, exists);
|
|
1574
1574
|
}
|
|
1575
1575
|
static boot() {}
|
|
1576
1576
|
static addGlobalScope(_name, scope) {
|
|
1577
|
-
ensureBooted(
|
|
1578
|
-
const existing = modelGlobalScopes.get(
|
|
1579
|
-
modelGlobalScopes.set(
|
|
1577
|
+
ensureBooted(this);
|
|
1578
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1579
|
+
modelGlobalScopes.set(this, [
|
|
1580
1580
|
...existing,
|
|
1581
1581
|
scope
|
|
1582
1582
|
]);
|
|
@@ -1586,17 +1586,17 @@ class Model {
|
|
|
1586
1586
|
}
|
|
1587
1587
|
static query() {
|
|
1588
1588
|
ensureBooted(this);
|
|
1589
|
-
const repository = resolveModelRepository(
|
|
1589
|
+
const repository = resolveModelRepository(this);
|
|
1590
1590
|
let query = repository.query();
|
|
1591
|
-
for (const scope of getGlobalScopes(
|
|
1591
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1592
1592
|
query = scope(query);
|
|
1593
1593
|
}
|
|
1594
1594
|
return query;
|
|
1595
1595
|
}
|
|
1596
1596
|
static async create(attributes) {
|
|
1597
1597
|
const statics = modelStatics(this);
|
|
1598
|
-
ensureBooted(
|
|
1599
|
-
const repository = resolveModelRepository(
|
|
1598
|
+
ensureBooted(this);
|
|
1599
|
+
const repository = resolveModelRepository(this);
|
|
1600
1600
|
const table = repository.getTable();
|
|
1601
1601
|
const timestamps = statics.$timestamps ?? true;
|
|
1602
1602
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1607,22 +1607,22 @@ class Model {
|
|
|
1607
1607
|
}
|
|
1608
1608
|
static async find(id) {
|
|
1609
1609
|
const statics = modelStatics(this);
|
|
1610
|
-
const repository = resolveModelRepository(
|
|
1611
|
-
const primaryKey =
|
|
1612
|
-
const record = await Model.query.call(
|
|
1610
|
+
const repository = resolveModelRepository(this);
|
|
1611
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1612
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1613
1613
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1614
1614
|
}
|
|
1615
1615
|
static async findOrFail(id, errorFactory) {
|
|
1616
|
-
const model = await Model.find.call(
|
|
1616
|
+
const model = await Model.find.call(this, id);
|
|
1617
1617
|
if (model) {
|
|
1618
1618
|
return model;
|
|
1619
1619
|
}
|
|
1620
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1620
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1621
1621
|
}
|
|
1622
1622
|
static async all(options = {}) {
|
|
1623
1623
|
const statics = modelStatics(this);
|
|
1624
|
-
const repository = resolveModelRepository(
|
|
1625
|
-
let query = Model.query.call(
|
|
1624
|
+
const repository = resolveModelRepository(this);
|
|
1625
|
+
let query = Model.query.call(this);
|
|
1626
1626
|
if (options.orderBy) {
|
|
1627
1627
|
query = query.orderBy(options.orderBy);
|
|
1628
1628
|
}
|
|
@@ -1634,8 +1634,8 @@ class Model {
|
|
|
1634
1634
|
}
|
|
1635
1635
|
static async firstWhere(where, options = {}) {
|
|
1636
1636
|
const statics = modelStatics(this);
|
|
1637
|
-
const repository = resolveModelRepository(
|
|
1638
|
-
let query = Model.query.call(
|
|
1637
|
+
const repository = resolveModelRepository(this);
|
|
1638
|
+
let query = Model.query.call(this).where(where);
|
|
1639
1639
|
if (options.orderBy) {
|
|
1640
1640
|
query = query.orderBy(options.orderBy);
|
|
1641
1641
|
}
|
package/dist/entries/database.js
CHANGED
|
@@ -1355,26 +1355,26 @@ class Model {
|
|
|
1355
1355
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1356
1356
|
}
|
|
1357
1357
|
static primaryKeyField() {
|
|
1358
|
-
return resolveModelRepository(
|
|
1358
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1359
1359
|
}
|
|
1360
1360
|
static hydrateAttributes(attributes) {
|
|
1361
|
-
const casts = modelStatics(
|
|
1361
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1362
1362
|
return applyCasts(attributes, casts, "hydrate");
|
|
1363
1363
|
}
|
|
1364
1364
|
static dehydrateAttributes(attributes) {
|
|
1365
|
-
const casts = modelStatics(
|
|
1365
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1366
1366
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1367
1367
|
}
|
|
1368
1368
|
static fromRecord(record, repository, exists = true) {
|
|
1369
|
-
const statics = modelStatics(
|
|
1369
|
+
const statics = modelStatics(this);
|
|
1370
1370
|
const hydrated = statics.hydrateAttributes(record);
|
|
1371
1371
|
return new statics(hydrated, repository, exists);
|
|
1372
1372
|
}
|
|
1373
1373
|
static boot() {}
|
|
1374
1374
|
static addGlobalScope(_name, scope) {
|
|
1375
|
-
ensureBooted(
|
|
1376
|
-
const existing = modelGlobalScopes.get(
|
|
1377
|
-
modelGlobalScopes.set(
|
|
1375
|
+
ensureBooted(this);
|
|
1376
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1377
|
+
modelGlobalScopes.set(this, [
|
|
1378
1378
|
...existing,
|
|
1379
1379
|
scope
|
|
1380
1380
|
]);
|
|
@@ -1384,17 +1384,17 @@ class Model {
|
|
|
1384
1384
|
}
|
|
1385
1385
|
static query() {
|
|
1386
1386
|
ensureBooted(this);
|
|
1387
|
-
const repository = resolveModelRepository(
|
|
1387
|
+
const repository = resolveModelRepository(this);
|
|
1388
1388
|
let query = repository.query();
|
|
1389
|
-
for (const scope of getGlobalScopes(
|
|
1389
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1390
1390
|
query = scope(query);
|
|
1391
1391
|
}
|
|
1392
1392
|
return query;
|
|
1393
1393
|
}
|
|
1394
1394
|
static async create(attributes) {
|
|
1395
1395
|
const statics = modelStatics(this);
|
|
1396
|
-
ensureBooted(
|
|
1397
|
-
const repository = resolveModelRepository(
|
|
1396
|
+
ensureBooted(this);
|
|
1397
|
+
const repository = resolveModelRepository(this);
|
|
1398
1398
|
const table = repository.getTable();
|
|
1399
1399
|
const timestamps = statics.$timestamps ?? true;
|
|
1400
1400
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1405,22 +1405,22 @@ class Model {
|
|
|
1405
1405
|
}
|
|
1406
1406
|
static async find(id) {
|
|
1407
1407
|
const statics = modelStatics(this);
|
|
1408
|
-
const repository = resolveModelRepository(
|
|
1409
|
-
const primaryKey =
|
|
1410
|
-
const record = await Model.query.call(
|
|
1408
|
+
const repository = resolveModelRepository(this);
|
|
1409
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1410
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1411
1411
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1412
1412
|
}
|
|
1413
1413
|
static async findOrFail(id, errorFactory) {
|
|
1414
|
-
const model = await Model.find.call(
|
|
1414
|
+
const model = await Model.find.call(this, id);
|
|
1415
1415
|
if (model) {
|
|
1416
1416
|
return model;
|
|
1417
1417
|
}
|
|
1418
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1418
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1419
1419
|
}
|
|
1420
1420
|
static async all(options = {}) {
|
|
1421
1421
|
const statics = modelStatics(this);
|
|
1422
|
-
const repository = resolveModelRepository(
|
|
1423
|
-
let query = Model.query.call(
|
|
1422
|
+
const repository = resolveModelRepository(this);
|
|
1423
|
+
let query = Model.query.call(this);
|
|
1424
1424
|
if (options.orderBy) {
|
|
1425
1425
|
query = query.orderBy(options.orderBy);
|
|
1426
1426
|
}
|
|
@@ -1432,8 +1432,8 @@ class Model {
|
|
|
1432
1432
|
}
|
|
1433
1433
|
static async firstWhere(where, options = {}) {
|
|
1434
1434
|
const statics = modelStatics(this);
|
|
1435
|
-
const repository = resolveModelRepository(
|
|
1436
|
-
let query = Model.query.call(
|
|
1435
|
+
const repository = resolveModelRepository(this);
|
|
1436
|
+
let query = Model.query.call(this).where(where);
|
|
1437
1437
|
if (options.orderBy) {
|
|
1438
1438
|
query = query.orderBy(options.orderBy);
|
|
1439
1439
|
}
|
|
@@ -1579,26 +1579,26 @@ class Model {
|
|
|
1579
1579
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1580
1580
|
}
|
|
1581
1581
|
static primaryKeyField() {
|
|
1582
|
-
return resolveModelRepository(
|
|
1582
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1583
1583
|
}
|
|
1584
1584
|
static hydrateAttributes(attributes) {
|
|
1585
|
-
const casts = modelStatics(
|
|
1585
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1586
1586
|
return applyCasts(attributes, casts, "hydrate");
|
|
1587
1587
|
}
|
|
1588
1588
|
static dehydrateAttributes(attributes) {
|
|
1589
|
-
const casts = modelStatics(
|
|
1589
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1590
1590
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1591
1591
|
}
|
|
1592
1592
|
static fromRecord(record, repository, exists = true) {
|
|
1593
|
-
const statics = modelStatics(
|
|
1593
|
+
const statics = modelStatics(this);
|
|
1594
1594
|
const hydrated = statics.hydrateAttributes(record);
|
|
1595
1595
|
return new statics(hydrated, repository, exists);
|
|
1596
1596
|
}
|
|
1597
1597
|
static boot() {}
|
|
1598
1598
|
static addGlobalScope(_name, scope) {
|
|
1599
|
-
ensureBooted(
|
|
1600
|
-
const existing = modelGlobalScopes.get(
|
|
1601
|
-
modelGlobalScopes.set(
|
|
1599
|
+
ensureBooted(this);
|
|
1600
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1601
|
+
modelGlobalScopes.set(this, [
|
|
1602
1602
|
...existing,
|
|
1603
1603
|
scope
|
|
1604
1604
|
]);
|
|
@@ -1608,17 +1608,17 @@ class Model {
|
|
|
1608
1608
|
}
|
|
1609
1609
|
static query() {
|
|
1610
1610
|
ensureBooted(this);
|
|
1611
|
-
const repository = resolveModelRepository(
|
|
1611
|
+
const repository = resolveModelRepository(this);
|
|
1612
1612
|
let query = repository.query();
|
|
1613
|
-
for (const scope of getGlobalScopes(
|
|
1613
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1614
1614
|
query = scope(query);
|
|
1615
1615
|
}
|
|
1616
1616
|
return query;
|
|
1617
1617
|
}
|
|
1618
1618
|
static async create(attributes) {
|
|
1619
1619
|
const statics = modelStatics(this);
|
|
1620
|
-
ensureBooted(
|
|
1621
|
-
const repository = resolveModelRepository(
|
|
1620
|
+
ensureBooted(this);
|
|
1621
|
+
const repository = resolveModelRepository(this);
|
|
1622
1622
|
const table = repository.getTable();
|
|
1623
1623
|
const timestamps = statics.$timestamps ?? true;
|
|
1624
1624
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1629,22 +1629,22 @@ class Model {
|
|
|
1629
1629
|
}
|
|
1630
1630
|
static async find(id) {
|
|
1631
1631
|
const statics = modelStatics(this);
|
|
1632
|
-
const repository = resolveModelRepository(
|
|
1633
|
-
const primaryKey =
|
|
1634
|
-
const record = await Model.query.call(
|
|
1632
|
+
const repository = resolveModelRepository(this);
|
|
1633
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1634
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1635
1635
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1636
1636
|
}
|
|
1637
1637
|
static async findOrFail(id, errorFactory) {
|
|
1638
|
-
const model = await Model.find.call(
|
|
1638
|
+
const model = await Model.find.call(this, id);
|
|
1639
1639
|
if (model) {
|
|
1640
1640
|
return model;
|
|
1641
1641
|
}
|
|
1642
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1642
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1643
1643
|
}
|
|
1644
1644
|
static async all(options = {}) {
|
|
1645
1645
|
const statics = modelStatics(this);
|
|
1646
|
-
const repository = resolveModelRepository(
|
|
1647
|
-
let query = Model.query.call(
|
|
1646
|
+
const repository = resolveModelRepository(this);
|
|
1647
|
+
let query = Model.query.call(this);
|
|
1648
1648
|
if (options.orderBy) {
|
|
1649
1649
|
query = query.orderBy(options.orderBy);
|
|
1650
1650
|
}
|
|
@@ -1656,8 +1656,8 @@ class Model {
|
|
|
1656
1656
|
}
|
|
1657
1657
|
static async firstWhere(where, options = {}) {
|
|
1658
1658
|
const statics = modelStatics(this);
|
|
1659
|
-
const repository = resolveModelRepository(
|
|
1660
|
-
let query = Model.query.call(
|
|
1659
|
+
const repository = resolveModelRepository(this);
|
|
1660
|
+
let query = Model.query.call(this).where(where);
|
|
1661
1661
|
if (options.orderBy) {
|
|
1662
1662
|
query = query.orderBy(options.orderBy);
|
|
1663
1663
|
}
|
package/dist/entries/http.js
CHANGED
|
@@ -1579,26 +1579,26 @@ class Model {
|
|
|
1579
1579
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1580
1580
|
}
|
|
1581
1581
|
static primaryKeyField() {
|
|
1582
|
-
return resolveModelRepository(
|
|
1582
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1583
1583
|
}
|
|
1584
1584
|
static hydrateAttributes(attributes) {
|
|
1585
|
-
const casts = modelStatics(
|
|
1585
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1586
1586
|
return applyCasts(attributes, casts, "hydrate");
|
|
1587
1587
|
}
|
|
1588
1588
|
static dehydrateAttributes(attributes) {
|
|
1589
|
-
const casts = modelStatics(
|
|
1589
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1590
1590
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1591
1591
|
}
|
|
1592
1592
|
static fromRecord(record, repository, exists = true) {
|
|
1593
|
-
const statics = modelStatics(
|
|
1593
|
+
const statics = modelStatics(this);
|
|
1594
1594
|
const hydrated = statics.hydrateAttributes(record);
|
|
1595
1595
|
return new statics(hydrated, repository, exists);
|
|
1596
1596
|
}
|
|
1597
1597
|
static boot() {}
|
|
1598
1598
|
static addGlobalScope(_name, scope) {
|
|
1599
|
-
ensureBooted(
|
|
1600
|
-
const existing = modelGlobalScopes.get(
|
|
1601
|
-
modelGlobalScopes.set(
|
|
1599
|
+
ensureBooted(this);
|
|
1600
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1601
|
+
modelGlobalScopes.set(this, [
|
|
1602
1602
|
...existing,
|
|
1603
1603
|
scope
|
|
1604
1604
|
]);
|
|
@@ -1608,17 +1608,17 @@ class Model {
|
|
|
1608
1608
|
}
|
|
1609
1609
|
static query() {
|
|
1610
1610
|
ensureBooted(this);
|
|
1611
|
-
const repository = resolveModelRepository(
|
|
1611
|
+
const repository = resolveModelRepository(this);
|
|
1612
1612
|
let query = repository.query();
|
|
1613
|
-
for (const scope of getGlobalScopes(
|
|
1613
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1614
1614
|
query = scope(query);
|
|
1615
1615
|
}
|
|
1616
1616
|
return query;
|
|
1617
1617
|
}
|
|
1618
1618
|
static async create(attributes) {
|
|
1619
1619
|
const statics = modelStatics(this);
|
|
1620
|
-
ensureBooted(
|
|
1621
|
-
const repository = resolveModelRepository(
|
|
1620
|
+
ensureBooted(this);
|
|
1621
|
+
const repository = resolveModelRepository(this);
|
|
1622
1622
|
const table = repository.getTable();
|
|
1623
1623
|
const timestamps = statics.$timestamps ?? true;
|
|
1624
1624
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1629,22 +1629,22 @@ class Model {
|
|
|
1629
1629
|
}
|
|
1630
1630
|
static async find(id) {
|
|
1631
1631
|
const statics = modelStatics(this);
|
|
1632
|
-
const repository = resolveModelRepository(
|
|
1633
|
-
const primaryKey =
|
|
1634
|
-
const record = await Model.query.call(
|
|
1632
|
+
const repository = resolveModelRepository(this);
|
|
1633
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1634
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1635
1635
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1636
1636
|
}
|
|
1637
1637
|
static async findOrFail(id, errorFactory) {
|
|
1638
|
-
const model = await Model.find.call(
|
|
1638
|
+
const model = await Model.find.call(this, id);
|
|
1639
1639
|
if (model) {
|
|
1640
1640
|
return model;
|
|
1641
1641
|
}
|
|
1642
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1642
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1643
1643
|
}
|
|
1644
1644
|
static async all(options = {}) {
|
|
1645
1645
|
const statics = modelStatics(this);
|
|
1646
|
-
const repository = resolveModelRepository(
|
|
1647
|
-
let query = Model.query.call(
|
|
1646
|
+
const repository = resolveModelRepository(this);
|
|
1647
|
+
let query = Model.query.call(this);
|
|
1648
1648
|
if (options.orderBy) {
|
|
1649
1649
|
query = query.orderBy(options.orderBy);
|
|
1650
1650
|
}
|
|
@@ -1656,8 +1656,8 @@ class Model {
|
|
|
1656
1656
|
}
|
|
1657
1657
|
static async firstWhere(where, options = {}) {
|
|
1658
1658
|
const statics = modelStatics(this);
|
|
1659
|
-
const repository = resolveModelRepository(
|
|
1660
|
-
let query = Model.query.call(
|
|
1659
|
+
const repository = resolveModelRepository(this);
|
|
1660
|
+
let query = Model.query.call(this).where(where);
|
|
1661
1661
|
if (options.orderBy) {
|
|
1662
1662
|
query = query.orderBy(options.orderBy);
|
|
1663
1663
|
}
|
|
@@ -1750,26 +1750,26 @@ class Model {
|
|
|
1750
1750
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1751
1751
|
}
|
|
1752
1752
|
static primaryKeyField() {
|
|
1753
|
-
return resolveModelRepository(
|
|
1753
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1754
1754
|
}
|
|
1755
1755
|
static hydrateAttributes(attributes) {
|
|
1756
|
-
const casts = modelStatics(
|
|
1756
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1757
1757
|
return applyCasts(attributes, casts, "hydrate");
|
|
1758
1758
|
}
|
|
1759
1759
|
static dehydrateAttributes(attributes) {
|
|
1760
|
-
const casts = modelStatics(
|
|
1760
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1761
1761
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1762
1762
|
}
|
|
1763
1763
|
static fromRecord(record, repository, exists = true) {
|
|
1764
|
-
const statics = modelStatics(
|
|
1764
|
+
const statics = modelStatics(this);
|
|
1765
1765
|
const hydrated = statics.hydrateAttributes(record);
|
|
1766
1766
|
return new statics(hydrated, repository, exists);
|
|
1767
1767
|
}
|
|
1768
1768
|
static boot() {}
|
|
1769
1769
|
static addGlobalScope(_name, scope) {
|
|
1770
|
-
ensureBooted(
|
|
1771
|
-
const existing = modelGlobalScopes.get(
|
|
1772
|
-
modelGlobalScopes.set(
|
|
1770
|
+
ensureBooted(this);
|
|
1771
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1772
|
+
modelGlobalScopes.set(this, [
|
|
1773
1773
|
...existing,
|
|
1774
1774
|
scope
|
|
1775
1775
|
]);
|
|
@@ -1779,17 +1779,17 @@ class Model {
|
|
|
1779
1779
|
}
|
|
1780
1780
|
static query() {
|
|
1781
1781
|
ensureBooted(this);
|
|
1782
|
-
const repository = resolveModelRepository(
|
|
1782
|
+
const repository = resolveModelRepository(this);
|
|
1783
1783
|
let query = repository.query();
|
|
1784
|
-
for (const scope of getGlobalScopes(
|
|
1784
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1785
1785
|
query = scope(query);
|
|
1786
1786
|
}
|
|
1787
1787
|
return query;
|
|
1788
1788
|
}
|
|
1789
1789
|
static async create(attributes) {
|
|
1790
1790
|
const statics = modelStatics(this);
|
|
1791
|
-
ensureBooted(
|
|
1792
|
-
const repository = resolveModelRepository(
|
|
1791
|
+
ensureBooted(this);
|
|
1792
|
+
const repository = resolveModelRepository(this);
|
|
1793
1793
|
const table = repository.getTable();
|
|
1794
1794
|
const timestamps = statics.$timestamps ?? true;
|
|
1795
1795
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1800,22 +1800,22 @@ class Model {
|
|
|
1800
1800
|
}
|
|
1801
1801
|
static async find(id) {
|
|
1802
1802
|
const statics = modelStatics(this);
|
|
1803
|
-
const repository = resolveModelRepository(
|
|
1804
|
-
const primaryKey =
|
|
1805
|
-
const record = await Model.query.call(
|
|
1803
|
+
const repository = resolveModelRepository(this);
|
|
1804
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1805
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1806
1806
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1807
1807
|
}
|
|
1808
1808
|
static async findOrFail(id, errorFactory) {
|
|
1809
|
-
const model = await Model.find.call(
|
|
1809
|
+
const model = await Model.find.call(this, id);
|
|
1810
1810
|
if (model) {
|
|
1811
1811
|
return model;
|
|
1812
1812
|
}
|
|
1813
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1813
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1814
1814
|
}
|
|
1815
1815
|
static async all(options = {}) {
|
|
1816
1816
|
const statics = modelStatics(this);
|
|
1817
|
-
const repository = resolveModelRepository(
|
|
1818
|
-
let query = Model.query.call(
|
|
1817
|
+
const repository = resolveModelRepository(this);
|
|
1818
|
+
let query = Model.query.call(this);
|
|
1819
1819
|
if (options.orderBy) {
|
|
1820
1820
|
query = query.orderBy(options.orderBy);
|
|
1821
1821
|
}
|
|
@@ -1827,8 +1827,8 @@ class Model {
|
|
|
1827
1827
|
}
|
|
1828
1828
|
static async firstWhere(where, options = {}) {
|
|
1829
1829
|
const statics = modelStatics(this);
|
|
1830
|
-
const repository = resolveModelRepository(
|
|
1831
|
-
let query = Model.query.call(
|
|
1830
|
+
const repository = resolveModelRepository(this);
|
|
1831
|
+
let query = Model.query.call(this).where(where);
|
|
1832
1832
|
if (options.orderBy) {
|
|
1833
1833
|
query = query.orderBy(options.orderBy);
|
|
1834
1834
|
}
|
|
@@ -1355,26 +1355,26 @@ class Model {
|
|
|
1355
1355
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1356
1356
|
}
|
|
1357
1357
|
static primaryKeyField() {
|
|
1358
|
-
return resolveModelRepository(
|
|
1358
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1359
1359
|
}
|
|
1360
1360
|
static hydrateAttributes(attributes) {
|
|
1361
|
-
const casts = modelStatics(
|
|
1361
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1362
1362
|
return applyCasts(attributes, casts, "hydrate");
|
|
1363
1363
|
}
|
|
1364
1364
|
static dehydrateAttributes(attributes) {
|
|
1365
|
-
const casts = modelStatics(
|
|
1365
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1366
1366
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1367
1367
|
}
|
|
1368
1368
|
static fromRecord(record, repository, exists = true) {
|
|
1369
|
-
const statics = modelStatics(
|
|
1369
|
+
const statics = modelStatics(this);
|
|
1370
1370
|
const hydrated = statics.hydrateAttributes(record);
|
|
1371
1371
|
return new statics(hydrated, repository, exists);
|
|
1372
1372
|
}
|
|
1373
1373
|
static boot() {}
|
|
1374
1374
|
static addGlobalScope(_name, scope) {
|
|
1375
|
-
ensureBooted(
|
|
1376
|
-
const existing = modelGlobalScopes.get(
|
|
1377
|
-
modelGlobalScopes.set(
|
|
1375
|
+
ensureBooted(this);
|
|
1376
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1377
|
+
modelGlobalScopes.set(this, [
|
|
1378
1378
|
...existing,
|
|
1379
1379
|
scope
|
|
1380
1380
|
]);
|
|
@@ -1384,17 +1384,17 @@ class Model {
|
|
|
1384
1384
|
}
|
|
1385
1385
|
static query() {
|
|
1386
1386
|
ensureBooted(this);
|
|
1387
|
-
const repository = resolveModelRepository(
|
|
1387
|
+
const repository = resolveModelRepository(this);
|
|
1388
1388
|
let query = repository.query();
|
|
1389
|
-
for (const scope of getGlobalScopes(
|
|
1389
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1390
1390
|
query = scope(query);
|
|
1391
1391
|
}
|
|
1392
1392
|
return query;
|
|
1393
1393
|
}
|
|
1394
1394
|
static async create(attributes) {
|
|
1395
1395
|
const statics = modelStatics(this);
|
|
1396
|
-
ensureBooted(
|
|
1397
|
-
const repository = resolveModelRepository(
|
|
1396
|
+
ensureBooted(this);
|
|
1397
|
+
const repository = resolveModelRepository(this);
|
|
1398
1398
|
const table = repository.getTable();
|
|
1399
1399
|
const timestamps = statics.$timestamps ?? true;
|
|
1400
1400
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1405,22 +1405,22 @@ class Model {
|
|
|
1405
1405
|
}
|
|
1406
1406
|
static async find(id) {
|
|
1407
1407
|
const statics = modelStatics(this);
|
|
1408
|
-
const repository = resolveModelRepository(
|
|
1409
|
-
const primaryKey =
|
|
1410
|
-
const record = await Model.query.call(
|
|
1408
|
+
const repository = resolveModelRepository(this);
|
|
1409
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1410
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1411
1411
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1412
1412
|
}
|
|
1413
1413
|
static async findOrFail(id, errorFactory) {
|
|
1414
|
-
const model = await Model.find.call(
|
|
1414
|
+
const model = await Model.find.call(this, id);
|
|
1415
1415
|
if (model) {
|
|
1416
1416
|
return model;
|
|
1417
1417
|
}
|
|
1418
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1418
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1419
1419
|
}
|
|
1420
1420
|
static async all(options = {}) {
|
|
1421
1421
|
const statics = modelStatics(this);
|
|
1422
|
-
const repository = resolveModelRepository(
|
|
1423
|
-
let query = Model.query.call(
|
|
1422
|
+
const repository = resolveModelRepository(this);
|
|
1423
|
+
let query = Model.query.call(this);
|
|
1424
1424
|
if (options.orderBy) {
|
|
1425
1425
|
query = query.orderBy(options.orderBy);
|
|
1426
1426
|
}
|
|
@@ -1432,8 +1432,8 @@ class Model {
|
|
|
1432
1432
|
}
|
|
1433
1433
|
static async firstWhere(where, options = {}) {
|
|
1434
1434
|
const statics = modelStatics(this);
|
|
1435
|
-
const repository = resolveModelRepository(
|
|
1436
|
-
let query = Model.query.call(
|
|
1435
|
+
const repository = resolveModelRepository(this);
|
|
1436
|
+
let query = Model.query.call(this).where(where);
|
|
1437
1437
|
if (options.orderBy) {
|
|
1438
1438
|
query = query.orderBy(options.orderBy);
|
|
1439
1439
|
}
|
|
@@ -1760,26 +1760,26 @@ class Model {
|
|
|
1760
1760
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1761
1761
|
}
|
|
1762
1762
|
static primaryKeyField() {
|
|
1763
|
-
return resolveModelRepository(
|
|
1763
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1764
1764
|
}
|
|
1765
1765
|
static hydrateAttributes(attributes) {
|
|
1766
|
-
const casts = modelStatics(
|
|
1766
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1767
1767
|
return applyCasts(attributes, casts, "hydrate");
|
|
1768
1768
|
}
|
|
1769
1769
|
static dehydrateAttributes(attributes) {
|
|
1770
|
-
const casts = modelStatics(
|
|
1770
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1771
1771
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1772
1772
|
}
|
|
1773
1773
|
static fromRecord(record, repository, exists = true) {
|
|
1774
|
-
const statics = modelStatics(
|
|
1774
|
+
const statics = modelStatics(this);
|
|
1775
1775
|
const hydrated = statics.hydrateAttributes(record);
|
|
1776
1776
|
return new statics(hydrated, repository, exists);
|
|
1777
1777
|
}
|
|
1778
1778
|
static boot() {}
|
|
1779
1779
|
static addGlobalScope(_name, scope) {
|
|
1780
|
-
ensureBooted(
|
|
1781
|
-
const existing = modelGlobalScopes.get(
|
|
1782
|
-
modelGlobalScopes.set(
|
|
1780
|
+
ensureBooted(this);
|
|
1781
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1782
|
+
modelGlobalScopes.set(this, [
|
|
1783
1783
|
...existing,
|
|
1784
1784
|
scope
|
|
1785
1785
|
]);
|
|
@@ -1789,17 +1789,17 @@ class Model {
|
|
|
1789
1789
|
}
|
|
1790
1790
|
static query() {
|
|
1791
1791
|
ensureBooted(this);
|
|
1792
|
-
const repository = resolveModelRepository(
|
|
1792
|
+
const repository = resolveModelRepository(this);
|
|
1793
1793
|
let query = repository.query();
|
|
1794
|
-
for (const scope of getGlobalScopes(
|
|
1794
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1795
1795
|
query = scope(query);
|
|
1796
1796
|
}
|
|
1797
1797
|
return query;
|
|
1798
1798
|
}
|
|
1799
1799
|
static async create(attributes) {
|
|
1800
1800
|
const statics = modelStatics(this);
|
|
1801
|
-
ensureBooted(
|
|
1802
|
-
const repository = resolveModelRepository(
|
|
1801
|
+
ensureBooted(this);
|
|
1802
|
+
const repository = resolveModelRepository(this);
|
|
1803
1803
|
const table = repository.getTable();
|
|
1804
1804
|
const timestamps = statics.$timestamps ?? true;
|
|
1805
1805
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1810,22 +1810,22 @@ class Model {
|
|
|
1810
1810
|
}
|
|
1811
1811
|
static async find(id) {
|
|
1812
1812
|
const statics = modelStatics(this);
|
|
1813
|
-
const repository = resolveModelRepository(
|
|
1814
|
-
const primaryKey =
|
|
1815
|
-
const record = await Model.query.call(
|
|
1813
|
+
const repository = resolveModelRepository(this);
|
|
1814
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1815
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1816
1816
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1817
1817
|
}
|
|
1818
1818
|
static async findOrFail(id, errorFactory) {
|
|
1819
|
-
const model = await Model.find.call(
|
|
1819
|
+
const model = await Model.find.call(this, id);
|
|
1820
1820
|
if (model) {
|
|
1821
1821
|
return model;
|
|
1822
1822
|
}
|
|
1823
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1823
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1824
1824
|
}
|
|
1825
1825
|
static async all(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);
|
|
1829
1829
|
if (options.orderBy) {
|
|
1830
1830
|
query = query.orderBy(options.orderBy);
|
|
1831
1831
|
}
|
|
@@ -1837,8 +1837,8 @@ class Model {
|
|
|
1837
1837
|
}
|
|
1838
1838
|
static async firstWhere(where, options = {}) {
|
|
1839
1839
|
const statics = modelStatics(this);
|
|
1840
|
-
const repository = resolveModelRepository(
|
|
1841
|
-
let query = Model.query.call(
|
|
1840
|
+
const repository = resolveModelRepository(this);
|
|
1841
|
+
let query = Model.query.call(this).where(where);
|
|
1842
1842
|
if (options.orderBy) {
|
|
1843
1843
|
query = query.orderBy(options.orderBy);
|
|
1844
1844
|
}
|
package/dist/entries/view.js
CHANGED
|
@@ -1564,26 +1564,26 @@ class Model {
|
|
|
1564
1564
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1565
1565
|
}
|
|
1566
1566
|
static primaryKeyField() {
|
|
1567
|
-
return resolveModelRepository(
|
|
1567
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1568
1568
|
}
|
|
1569
1569
|
static hydrateAttributes(attributes) {
|
|
1570
|
-
const casts = modelStatics(
|
|
1570
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1571
1571
|
return applyCasts(attributes, casts, "hydrate");
|
|
1572
1572
|
}
|
|
1573
1573
|
static dehydrateAttributes(attributes) {
|
|
1574
|
-
const casts = modelStatics(
|
|
1574
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1575
1575
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1576
1576
|
}
|
|
1577
1577
|
static fromRecord(record, repository, exists = true) {
|
|
1578
|
-
const statics = modelStatics(
|
|
1578
|
+
const statics = modelStatics(this);
|
|
1579
1579
|
const hydrated = statics.hydrateAttributes(record);
|
|
1580
1580
|
return new statics(hydrated, repository, exists);
|
|
1581
1581
|
}
|
|
1582
1582
|
static boot() {}
|
|
1583
1583
|
static addGlobalScope(_name, scope) {
|
|
1584
|
-
ensureBooted(
|
|
1585
|
-
const existing = modelGlobalScopes.get(
|
|
1586
|
-
modelGlobalScopes.set(
|
|
1584
|
+
ensureBooted(this);
|
|
1585
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1586
|
+
modelGlobalScopes.set(this, [
|
|
1587
1587
|
...existing,
|
|
1588
1588
|
scope
|
|
1589
1589
|
]);
|
|
@@ -1593,17 +1593,17 @@ class Model {
|
|
|
1593
1593
|
}
|
|
1594
1594
|
static query() {
|
|
1595
1595
|
ensureBooted(this);
|
|
1596
|
-
const repository = resolveModelRepository(
|
|
1596
|
+
const repository = resolveModelRepository(this);
|
|
1597
1597
|
let query = repository.query();
|
|
1598
|
-
for (const scope of getGlobalScopes(
|
|
1598
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1599
1599
|
query = scope(query);
|
|
1600
1600
|
}
|
|
1601
1601
|
return query;
|
|
1602
1602
|
}
|
|
1603
1603
|
static async create(attributes) {
|
|
1604
1604
|
const statics = modelStatics(this);
|
|
1605
|
-
ensureBooted(
|
|
1606
|
-
const repository = resolveModelRepository(
|
|
1605
|
+
ensureBooted(this);
|
|
1606
|
+
const repository = resolveModelRepository(this);
|
|
1607
1607
|
const table = repository.getTable();
|
|
1608
1608
|
const timestamps = statics.$timestamps ?? true;
|
|
1609
1609
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1614,22 +1614,22 @@ class Model {
|
|
|
1614
1614
|
}
|
|
1615
1615
|
static async find(id) {
|
|
1616
1616
|
const statics = modelStatics(this);
|
|
1617
|
-
const repository = resolveModelRepository(
|
|
1618
|
-
const primaryKey =
|
|
1619
|
-
const record = await Model.query.call(
|
|
1617
|
+
const repository = resolveModelRepository(this);
|
|
1618
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1619
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1620
1620
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1621
1621
|
}
|
|
1622
1622
|
static async findOrFail(id, errorFactory) {
|
|
1623
|
-
const model = await Model.find.call(
|
|
1623
|
+
const model = await Model.find.call(this, id);
|
|
1624
1624
|
if (model) {
|
|
1625
1625
|
return model;
|
|
1626
1626
|
}
|
|
1627
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1627
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1628
1628
|
}
|
|
1629
1629
|
static async all(options = {}) {
|
|
1630
1630
|
const statics = modelStatics(this);
|
|
1631
|
-
const repository = resolveModelRepository(
|
|
1632
|
-
let query = Model.query.call(
|
|
1631
|
+
const repository = resolveModelRepository(this);
|
|
1632
|
+
let query = Model.query.call(this);
|
|
1633
1633
|
if (options.orderBy) {
|
|
1634
1634
|
query = query.orderBy(options.orderBy);
|
|
1635
1635
|
}
|
|
@@ -1641,8 +1641,8 @@ class Model {
|
|
|
1641
1641
|
}
|
|
1642
1642
|
static async firstWhere(where, 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).where(where);
|
|
1646
1646
|
if (options.orderBy) {
|
|
1647
1647
|
query = query.orderBy(options.orderBy);
|
|
1648
1648
|
}
|
package/dist/index.js
CHANGED
|
@@ -1665,26 +1665,26 @@ class Model {
|
|
|
1665
1665
|
throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
|
|
1666
1666
|
}
|
|
1667
1667
|
static primaryKeyField() {
|
|
1668
|
-
return resolveModelRepository(
|
|
1668
|
+
return resolveModelRepository(this).getTable().primaryKey;
|
|
1669
1669
|
}
|
|
1670
1670
|
static hydrateAttributes(attributes) {
|
|
1671
|
-
const casts = modelStatics(
|
|
1671
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1672
1672
|
return applyCasts(attributes, casts, "hydrate");
|
|
1673
1673
|
}
|
|
1674
1674
|
static dehydrateAttributes(attributes) {
|
|
1675
|
-
const casts = modelStatics(
|
|
1675
|
+
const casts = modelStatics(this).$casts ?? {};
|
|
1676
1676
|
return applyCasts(attributes, casts, "dehydrate");
|
|
1677
1677
|
}
|
|
1678
1678
|
static fromRecord(record, repository, exists = true) {
|
|
1679
|
-
const statics = modelStatics(
|
|
1679
|
+
const statics = modelStatics(this);
|
|
1680
1680
|
const hydrated = statics.hydrateAttributes(record);
|
|
1681
1681
|
return new statics(hydrated, repository, exists);
|
|
1682
1682
|
}
|
|
1683
1683
|
static boot() {}
|
|
1684
1684
|
static addGlobalScope(_name, scope) {
|
|
1685
|
-
ensureBooted(
|
|
1686
|
-
const existing = modelGlobalScopes.get(
|
|
1687
|
-
modelGlobalScopes.set(
|
|
1685
|
+
ensureBooted(this);
|
|
1686
|
+
const existing = modelGlobalScopes.get(this) ?? [];
|
|
1687
|
+
modelGlobalScopes.set(this, [
|
|
1688
1688
|
...existing,
|
|
1689
1689
|
scope
|
|
1690
1690
|
]);
|
|
@@ -1694,17 +1694,17 @@ class Model {
|
|
|
1694
1694
|
}
|
|
1695
1695
|
static query() {
|
|
1696
1696
|
ensureBooted(this);
|
|
1697
|
-
const repository = resolveModelRepository(
|
|
1697
|
+
const repository = resolveModelRepository(this);
|
|
1698
1698
|
let query = repository.query();
|
|
1699
|
-
for (const scope of getGlobalScopes(
|
|
1699
|
+
for (const scope of getGlobalScopes(this)) {
|
|
1700
1700
|
query = scope(query);
|
|
1701
1701
|
}
|
|
1702
1702
|
return query;
|
|
1703
1703
|
}
|
|
1704
1704
|
static async create(attributes) {
|
|
1705
1705
|
const statics = modelStatics(this);
|
|
1706
|
-
ensureBooted(
|
|
1707
|
-
const repository = resolveModelRepository(
|
|
1706
|
+
ensureBooted(this);
|
|
1707
|
+
const repository = resolveModelRepository(this);
|
|
1708
1708
|
const table = repository.getTable();
|
|
1709
1709
|
const timestamps = statics.$timestamps ?? true;
|
|
1710
1710
|
const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
|
|
@@ -1715,22 +1715,22 @@ class Model {
|
|
|
1715
1715
|
}
|
|
1716
1716
|
static async find(id) {
|
|
1717
1717
|
const statics = modelStatics(this);
|
|
1718
|
-
const repository = resolveModelRepository(
|
|
1719
|
-
const primaryKey =
|
|
1720
|
-
const record = await Model.query.call(
|
|
1718
|
+
const repository = resolveModelRepository(this);
|
|
1719
|
+
const primaryKey = repository.getTable().primaryKey;
|
|
1720
|
+
const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
|
|
1721
1721
|
return record ? statics.fromRecord(record, repository, true) : null;
|
|
1722
1722
|
}
|
|
1723
1723
|
static async findOrFail(id, errorFactory) {
|
|
1724
|
-
const model = await Model.find.call(
|
|
1724
|
+
const model = await Model.find.call(this, id);
|
|
1725
1725
|
if (model) {
|
|
1726
1726
|
return model;
|
|
1727
1727
|
}
|
|
1728
|
-
throw errorFactory?.(id) ?? new NotFoundError(`${
|
|
1728
|
+
throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
|
|
1729
1729
|
}
|
|
1730
1730
|
static async all(options = {}) {
|
|
1731
1731
|
const statics = modelStatics(this);
|
|
1732
|
-
const repository = resolveModelRepository(
|
|
1733
|
-
let query = Model.query.call(
|
|
1732
|
+
const repository = resolveModelRepository(this);
|
|
1733
|
+
let query = Model.query.call(this);
|
|
1734
1734
|
if (options.orderBy) {
|
|
1735
1735
|
query = query.orderBy(options.orderBy);
|
|
1736
1736
|
}
|
|
@@ -1742,8 +1742,8 @@ class Model {
|
|
|
1742
1742
|
}
|
|
1743
1743
|
static async firstWhere(where, options = {}) {
|
|
1744
1744
|
const statics = modelStatics(this);
|
|
1745
|
-
const repository = resolveModelRepository(
|
|
1746
|
-
let query = Model.query.call(
|
|
1745
|
+
const repository = resolveModelRepository(this);
|
|
1746
|
+
let query = Model.query.call(this).where(where);
|
|
1747
1747
|
if (options.orderBy) {
|
|
1748
1748
|
query = query.orderBy(options.orderBy);
|
|
1749
1749
|
}
|