Hello If I have the following structure, when I cr...
# orm-help
m
Hello If I have the following structure, when I create the model it can be an Array or it has to be defined as JSON?
Copy code
const persons = [
	{
		id: 'cblablabla',
		name: 'John',
		relatives: [
			{ id: '1', name: 'Sara' },
			{ id: '2', name: 'Bob' },
		],
	},
	{
		id: 'cblebleble',
		name: 'Sara',
		relatives: [
			{ id: '1', name: 'John' },
			{ id: '3', name: 'Bob' },
		],
	},
];

model People {
  id        String   @id @default(cuid())
  name      String
  relatives String[] or JSON ?
}
1
y
This can be done in 3 ways friends -> Who I consider as friends friendOf -> Who considers me as a friend
Copy code
model Person {
  id       Int      @id @default(autoincrement())
  name     String
  friends  Person[] @relation("Friends")
  friendOf Person[] @relation("Friends")
}
friendship -> my circle of friends or something
Copy code
model Person {
  id           Int        @id @default(autoincrement())
  name         String
  friendship   Friendship @relation(fields: [friendshipId], references: [id])
  friendshipId Int

  // can also be m-n relation like for reasons
  friendships  Friendship[]
}

model Friendship {
  id      Int      @id @default(autoincrement())
  friends Person[]
}
friends -> the ID's of my friends
Copy code
model Person {
  id      Int    @id @default(autoincrement())
  name    String
  friends Int[]
}
I wouldn't do the last one, but it's what you suggested
💯 1
m
so the solution would be to make a relationship instead
So from a more specific case I have a form, which has one field that its composed on the following values
Copy code
{
		id: '1',
		code : 'GLU',
		description: 'Glu',
		title: 'Test for Glu',
		units: 'mg/dL',
		resultType: 'Numeric',
		textValue: '',
		rangeValue: [
			{
				id: '1',
				gender: "m",
				minValue: "1",
				maxValue: "100",
				minAge: '1',
				maxAge: '120'
			},
			{
				id: '2',
				gender: 'f',
				minValue: '1',
				maxValue: '90',
				minAge: '1',
				maxAge: '120'
			}
		],
	}
so I would need to make a model like this?
Copy code
model Test {
  id          String       @id @default(cuid())
  code        String
  description String
  title       String
  units       String
  resutlType  String
  textValue   String
  RangeValue  RangeValue[]
}

model RangeValue {
  id       String  @id @default(cuid())
  gender   String
  minValue Int
  maxValue Int
  minAge   Int
  maxAge   Int
  Test     Test?   @relation(fields: [testId], references: [id])
  testId   String?
}
a
Hey Max, the schema above looks good to me 👍
1