File tree 3 files changed +14
-2
lines changed
3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -680,6 +680,11 @@ declare module '@ioc:Adonis/Lucid/Model' {
680
680
Result extends any = InstanceType < Model > ,
681
681
> ( this : Model , options ?: ModelAdapterOptions ) : ModelQueryBuilderContract < Model , Result >
682
682
683
+ /**
684
+ * Truncate model table
685
+ */
686
+ truncate ( cascade ?: boolean ) : Promise < void >
687
+
683
688
new ( ) : Model
684
689
}
685
690
Original file line number Diff line number Diff line change @@ -648,6 +648,13 @@ export class BaseModel implements ModelContract {
648
648
return this . query ( options ) . orderBy ( this . primaryKey , 'desc' )
649
649
}
650
650
651
+ /**
652
+ * Truncate model table
653
+ */
654
+ public static truncate ( cascade : boolean = false ) {
655
+ return ( this as ModelConstructorContract ) . query ( ) . client . truncate ( this . table , cascade )
656
+ }
657
+
651
658
constructor ( ) {
652
659
return new Proxy ( this , proxyHandler )
653
660
}
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ test.group('Query client', (group) => {
80
80
81
81
const client = new QueryClient ( 'write' , connection )
82
82
const column = await client . columnsInfo ( 'users' , 'id' )
83
- assert . equal ( column . type , 'integer' )
83
+ assert . oneOf ( column . type , [ 'integer' , 'int' ] )
84
84
} )
85
85
86
86
test ( 'truncate table with cascade' , async ( _assert ) => {
@@ -96,7 +96,7 @@ test.group('Query client', (group) => {
96
96
} )
97
97
await connection . client ?. schema . createTableIfNotExists ( 'test_profiles' , ( table ) => {
98
98
table . increments ( 'id' ) . primary ( )
99
- table . integer ( 'user_id' ) . references ( 'test_users.id' ) . onDelete ( 'CASCADE' )
99
+ table . integer ( 'user_id' ) . unsigned ( ) . references ( 'test_users.id' ) . onDelete ( 'CASCADE' )
100
100
} )
101
101
102
102
/**
You can’t perform that action at this time.
0 commit comments