Skip to content

Commit c337128

Browse files
committed
chore: wip
1 parent f273dac commit c337128

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

storage/framework/core/database/src/drivers/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,11 @@ export async function getRelations(model: Model, modelPath: string): Promise<Rel
177177
relationModel = relationInstance
178178
}
179179

180-
const modelRelationPath = path.userModelsPath(`${relationModel}.ts`)
180+
const modelRelationPath = path.userModelsPath(relationModel)
181181
const modelRelation = (await import(modelRelationPath)).default
182-
183182
const modelName = getModelName(model, modelPath)
184183
const formattedModelName = modelName.toLowerCase()
185184
const tableName = getTableName(model, modelPath)
186-
187185
const modelRelationTable = getModelName(modelRelation, modelRelationPath)
188186

189187
relationships.push({
@@ -207,17 +205,13 @@ export async function getRelations(model: Model, modelPath: string): Promise<Rel
207205

208206
export async function fetchOtherModelRelations(model: Model, modelPath: string): Promise<RelationConfig[]> {
209207
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
210-
211208
const modelRelations = []
212209

213210
for (let i = 0; i < modelFiles.length; i++) {
214211
const modelFileElement = modelFiles[i] as string
215-
216212
const modelFile = (await import(modelFileElement)).default as Model
217-
218213
const tableName = getTableName(model, modelPath)
219214
const modelName = getModelName(model, modelPath)
220-
221215
const modelFileName = getTableName(modelFile, modelFileElement)
222216

223217
if (tableName === modelFileName) continue

storage/framework/core/types/src/model.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,20 @@ type Base = {}
6565
* Model.
6666
*/
6767
export interface ModelOptions extends Base {
68+
/**
69+
* The name of the model.
70+
*
71+
* @default string - The file name of the model.
72+
*/
6873
name: string // defaults to the file name of the model
69-
table: string // defaults to the lowercase, plural name of the model name (or the name of the model file)
74+
table?: string // defaults to the lowercase, plural name of the model name (or the name of the model file)
7075
primaryKey?: string // defaults to `id`
7176
autoIncrement?: boolean // defaults to true
7277
dashboard?: {
7378
highlight?: boolean | number // defaults to undefined
7479
}
7580

76-
traits: {
81+
traits?: {
7782
useUuid?: boolean // defaults to false
7883
useTimestamps?: boolean | TimestampOptions // defaults to true
7984
timestampable?: boolean | TimestampOptions // useTimestamps alias
@@ -91,44 +96,44 @@ export interface ModelOptions extends Base {
9196
useActivityLog?: boolean | ActivityLogOption
9297
}
9398

94-
attributes: Attributes
99+
attributes?: Attributes
95100

96101
// relationships
97-
hasOne:
102+
hasOne?:
98103
| {
99104
model: ModelNames
100105
foreignKey?: string
101106
relationName?: string
102107
}[]
103108
| string[]
104-
hasMany:
109+
hasMany?:
105110
| {
106111
model: ModelNames // should be typed as ModelName
107112
foreignKey?: string
108113
relationName?: string
109114
}[]
110115
| ModelNames[]
111-
belongsTo:
116+
belongsTo?:
112117
| {
113118
model: ModelNames // should be typed as ModelName
114119
foreignKey?: string
115120
relationName?: string
116121
}[]
117122
| ModelNames[] // belongsTo: 'User'
118-
belongsToMany: BelongsToManyType[] | ModelNames[]
119-
hasOneThrough: {
123+
belongsToMany?: BelongsToManyType[] | ModelNames[]
124+
hasOneThrough?: {
120125
model: ModelNames
121126
through: ModelNames
122127
foreignKey?: string
123128
throughForeignKey?: string
124129
relationName?: string
125130
}[]
126131

127-
get: {
132+
get?: {
128133
[key: string]: (value: any) => any
129134
}
130135

131-
set: {
136+
set?: {
132137
[key: string]: (value: any) => any
133138
}
134139
}

0 commit comments

Comments
 (0)