Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] develop from medusajs:develop #7

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-moles-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

chore(utils): DML#hasOne allow mappedBy to not be defined
9 changes: 5 additions & 4 deletions packages/core/types/src/dml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type KnownDataTypes =
*/
export type RelationshipTypes =
| "hasOne"
| "hasOneWithFK"
| "hasMany"
| "belongsTo"
| "manyToMany"
Expand Down Expand Up @@ -111,7 +112,7 @@ export type RelationshipMetadata = {
name: string
type: RelationshipTypes
entity: unknown
nullable: boolean
nullable?: boolean
mappedBy?: string
searchable: boolean
options: Record<string, any>
Expand Down Expand Up @@ -142,9 +143,9 @@ export interface EntityConstructor<Props> extends Function {
* "belongsTo" relation meaning "hasOne" and "ManyToOne"
*/
export type InferForeignKeys<Schema extends DMLSchema> = {
[K in keyof Schema as Schema[K] extends { type: "belongsTo" }
[K in keyof Schema as Schema[K] extends { $foreignKey: true }
? `${K & string}_id`
: never]: Schema[K] extends { type: "belongsTo" }
: never]: Schema[K] extends { $foreignKey: true }
? null extends Schema[K]["$dataType"]
? string | null
: string
Expand Down Expand Up @@ -191,7 +192,7 @@ export type InferSchemaFields<Schema extends DMLSchema> = Prettify<
[K in keyof Schema]: Schema[K] extends RelationshipType<any>
? Schema[K]["type"] extends "belongsTo"
? InferBelongsToFields<Schema[K]["$dataType"]>
: Schema[K]["type"] extends "hasOne"
: Schema[K]["type"] extends "hasOne" | "hasOneWithFK"
? InferHasOneFields<Schema[K]["$dataType"]>
: Schema[K]["type"] extends "hasMany"
? InferHasManyFields<Schema[K]["$dataType"]>
Expand Down
Loading
Loading