outlet-orm 2.5.0 → 2.5.1
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 +24 -0
- package/package.json +1 -1
- package/src/Model.js +683 -659
- package/src/QueryBuilder.js +712 -710
- package/types/index.d.ts +4 -0
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ Si aucun driver n'est installé, un message d'erreur explicite vous indiquera le
|
|
|
33
33
|
- Relations: hasOne, hasMany, belongsTo, belongsToMany (avec attach/detach/sync)
|
|
34
34
|
- Casts automatiques (int, float, boolean, json, date...)
|
|
35
35
|
- Attributs masqués (`hidden`) et timestamps automatiques
|
|
36
|
+
- Contrôle de visibilité des attributs cachés: `withHidden()` et `withoutHidden()`
|
|
36
37
|
- Incrément/Décrément atomiques: `increment()` et `decrement()`
|
|
37
38
|
- Aliases ergonomiques: `columns([...])`, `ordrer()` (alias typo de `orderBy`)
|
|
38
39
|
- Requêtes brutes: `executeRawQuery()` et `execute()` (résultats natifs du driver)
|
|
@@ -438,6 +439,27 @@ const user = await User.find(1);
|
|
|
438
439
|
console.log(user.toJSON()); // password et secret_token ne sont pas inclus
|
|
439
440
|
```
|
|
440
441
|
|
|
442
|
+
#### Afficher les attributs cachés
|
|
443
|
+
|
|
444
|
+
Parfois, vous devez inclure les attributs cachés dans les résultats, par exemple lors de l'authentification :
|
|
445
|
+
|
|
446
|
+
```javascript
|
|
447
|
+
// Inclure les attributs cachés dans les résultats de la requête
|
|
448
|
+
const user = await User.withHidden().where('email', 'john@example.com').first();
|
|
449
|
+
console.log(user.toJSON()); // password est inclus
|
|
450
|
+
|
|
451
|
+
// Alternative : contrôler la visibilité avec un booléen
|
|
452
|
+
const userWithPassword = await User.withoutHidden(true).where('email', 'john@example.com').first();
|
|
453
|
+
// true = afficher les attributs cachés
|
|
454
|
+
// false (défaut) = masquer les attributs cachés
|
|
455
|
+
|
|
456
|
+
// Utilisation typique pour l'authentification
|
|
457
|
+
const user = await User.withHidden().where('email', email).first();
|
|
458
|
+
if (user && await bcrypt.compare(password, user.getAttribute('password'))) {
|
|
459
|
+
// Authentification réussie
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
441
463
|
### Timestamps
|
|
442
464
|
|
|
443
465
|
```javascript
|
|
@@ -527,6 +549,8 @@ class User extends Model {
|
|
|
527
549
|
- `static updateAndFetchById(id, attributes, relations?)` - Mise à jour par ID et retour du modèle (avec include)
|
|
528
550
|
- `static updateById(id, attributes)` - Mise à jour par ID
|
|
529
551
|
- `static delete()` - Suppression bulk
|
|
552
|
+
- `static withHidden()` - Inclure les attributs cachés dans les résultats
|
|
553
|
+
- `static withoutHidden(show?)` - Contrôler la visibilité des attributs cachés (false = masquer, true = afficher)
|
|
530
554
|
- `save()` - Sauvegarder l'instance
|
|
531
555
|
- `destroy()` - Supprimer l'instance
|
|
532
556
|
- `toJSON()` - Convertir en JSON
|