Skip to content

Commit a1dea74

Browse files
committed
chore: wip
1 parent da74c4a commit a1dea74

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

.stacks/core/types/src/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface ModelOptions extends Base {
3030
hasOne: string // hasOne: 'Post
3131
hasMany: {
3232
model: string // should be typed as ModelName
33-
foreignKey: string
33+
foreignKey?: string
3434
}
3535
belongsToMany: {}
3636
hasThrough: {

app/models/User.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { faker } from '@stacksjs/faker'
2-
import { validate } from '@stacksjs/validation'
2+
import { validator } from '@stacksjs/validation'
33
import { defineModel } from '@stacksjs/config'
44

55
export default defineModel({
66
name: 'User', // defaults to the sanitized file name
77
table: 'users', // defaults to the lowercase, plural name of the model
8-
8+
// primaryKey: 'id', // defaults to `id`
9+
// autoIncrement: true, // defaults to true
910
useUuid: true, // instead of `auto-incrementing id`, defaults to false
1011
searchable: true, // defaults to false, also accepts SearchEngineSettings
1112
seedable: { // defaults to a count of 10
@@ -17,7 +18,9 @@ export default defineModel({
1718
fields: {
1819
name: {
1920
validator: {
20-
rule: validate.string().minLength(3).maxLength(255).nullable(),
21+
// rule: validate.string('test').min(3).max(255),
22+
rule: validator.string().minLength(3).maxLength(255),
23+
default: 'test',
2124
message: 'Name must be between 3 and 255 characters',
2225
},
2326

@@ -26,7 +29,7 @@ export default defineModel({
2629

2730
status: {
2831
validator: {
29-
rule: validate.enum(['active', 'inactive']),
32+
rule: validator.enum(['active', 'inactive']),
3033
message: 'Status must be either active or inactive',
3134
},
3235

@@ -37,7 +40,7 @@ export default defineModel({
3740
unique: true,
3841

3942
validator: {
40-
rule: validate.string().email(),
43+
rule: validator.string().email(),
4144
message: 'Email must be a valid email address',
4245
},
4346

@@ -46,7 +49,7 @@ export default defineModel({
4649

4750
password: {
4851
validator: {
49-
rule: validate.string().minLength(6).maxLength(255),
52+
rule: validator.string().minLength(6).maxLength(255),
5053
message: 'Password must be between 6 and 255 characters',
5154
},
5255

0 commit comments

Comments
 (0)