Skip to content

Commit 6a7c0fe

Browse files
chore: wip
1 parent 617feaa commit 6a7c0fe

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

app/Models/User.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import type { UserType as User } from '@stacksjs/orm'
44
import { capitalize } from '@stacksjs/strings'
55
import type { Model } from '@stacksjs/types'
66
import { schema } from '@stacksjs/validation'
7-
import Post from './Post'
8-
import Subscriber from './Subscriber'
97

108
export default {
119
name: 'User', // defaults to the sanitized file name

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ export async function checkPivotMigration(dynamicPart: string): Promise<boolean>
103103

104104

105105
export async function getRelations(model: Model): Promise<RelationConfig[]> {
106-
const relationsArray = ['hasOne', 'belongsTo', 'hasMany', 'belongsToMany', 'hasOneThrough']
106+
const relationsArray = ['hasOne', 'hasMany', 'belongsToMany', 'hasOneThrough']
107107
const relationships = []
108108

109109
for (const relation of relationsArray) {
110110
if (hasRelations(model, relation)) {
111111
for (const relationInstance of model[relation]) {
112-
const modelRelationPath = path.userModelsPath(`${relationInstance.model.name}.ts`)
112+
const modelRelationPath = path.userModelsPath(`${relationInstance.model}.ts`)
113113
const modelRelation = (await import(modelRelationPath)).default
114114
const formattedModelName = model.name.toLowerCase()
115115

116116
relationships.push({
117117
relationship: relation,
118-
model: relationInstance.model.name,
118+
model: relationInstance.model,
119119
table: modelRelation.table,
120120
foreignKey: relationInstance.foreignKey || `${formattedModelName}_id`,
121121
relationName: relationInstance.relationName || '',
@@ -135,13 +135,13 @@ export async function fetchOtherModelRelations(model: Model, modelFiles: string[
135135

136136
for (let i = 0; i < modelFiles.length; i++) {
137137
const modelFileElement = modelFiles[i] as string
138-
138+
139139
const modelFile = await import(modelFileElement)
140140

141141
if (model.name === modelFile.default.name) continue
142142

143143
const relations = await getRelations(modelFile.default)
144-
144+
145145
if (! relations.length) continue
146146

147147
const relation = relations.find(relation => relation.model === model.name)

storage/framework/database/models/Post.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { faker } from '@stacksjs/faker'
22
import type { Model } from '@stacksjs/types'
33
import { schema } from '@stacksjs/validation'
4+
import User from './User'
45

56
export default {
67
name: 'Post', // defaults to the sanitized file name
@@ -15,7 +16,11 @@ export default {
1516
count: 10,
1617
},
1718
},
18-
19+
belongsTo: [
20+
{
21+
model: 'User'
22+
}
23+
],
1924
attributes: {
2025
title: {
2126
validator: {

storage/framework/database/models/User.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import type { UserType as User } from '@stacksjs/orm'
44
import { capitalize } from '@stacksjs/strings'
55
import type { Model } from '@stacksjs/types'
66
import { schema } from '@stacksjs/validation'
7-
import Post from './Post'
8-
import Subscriber from './Subscriber'
97

108
export default {
119
name: 'User', // defaults to the sanitized file name
@@ -42,13 +40,13 @@ export default {
4240

4341
hasMany: [
4442
{
45-
model: Post,
43+
model: 'Post',
4644
},
4745
],
4846

4947
hasOne: [
5048
{
51-
model: Subscriber,
49+
model: 'Subscriber',
5250
},
5351
],
5452

0 commit comments

Comments
 (0)