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

feat: add meta to all relations #1042

Merged
merged 2 commits into from
Nov 18, 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
3 changes: 3 additions & 0 deletions src/orm/relations/belongs_to/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class BelongsTo implements BelongsToRelationContract<LucidModel, LucidMod
*/
onQueryHook

declare meta?: any

constructor(
public relationName: string,
public relatedModel: () => LucidModel,
Expand All @@ -68,6 +70,7 @@ export class BelongsTo implements BelongsToRelationContract<LucidModel, LucidMod
this.onQueryHook = this.options.onQuery
this.serializeAs =
this.options.serializeAs === undefined ? this.relationName : this.options.serializeAs
this.meta = this.options.meta
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/orm/relations/has_many/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class HasMany implements HasManyRelationContract<LucidModel, LucidModel>
*/
onQueryHook

declare meta?: any

constructor(
public relationName: string,
public relatedModel: () => LucidModel,
Expand All @@ -70,6 +72,7 @@ export class HasMany implements HasManyRelationContract<LucidModel, LucidModel>
this.serializeAs =
this.options.serializeAs === undefined ? this.relationName : this.options.serializeAs
this.onQueryHook = this.options.onQuery
this.meta = this.options.meta
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/orm/relations/has_many_through/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class HasManyThrough implements HasManyThroughRelationContract<LucidModel
declare throughForeignKey: string
declare throughForeignKeyColumnName: string

declare meta?: any

constructor(
public relationName: string,
public relatedModel: () => LucidModel,
Expand All @@ -75,6 +77,7 @@ export class HasManyThrough implements HasManyThroughRelationContract<LucidModel
this.throughModel = this.options.throughModel
this.serializeAs =
this.options.serializeAs === undefined ? this.relationName : this.options.serializeAs
this.meta = this.options.meta
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/orm/relations/has_one/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class HasOne implements HasOneRelationContract<LucidModel, LucidModel> {
*/
onQueryHook

declare meta?: any

constructor(
public relationName: string,
public relatedModel: () => LucidModel,
Expand All @@ -57,6 +59,7 @@ export class HasOne implements HasOneRelationContract<LucidModel, LucidModel> {
this.onQueryHook = this.options.onQuery
this.serializeAs =
this.options.serializeAs === undefined ? this.relationName : this.options.serializeAs
this.meta = this.options.meta
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/orm/relations/many_to_many/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class ManyToMany implements ManyToManyRelationContract<LucidModel, LucidM
*/
onQueryHook

declare meta?: any

/**
* Computes the created at timestamps column name
* for the pivot table
Expand Down Expand Up @@ -114,6 +116,7 @@ export class ManyToMany implements ManyToManyRelationContract<LucidModel, LucidM
this.options.serializeAs === undefined ? this.relationName : this.options.serializeAs
this.pivotColumns = this.options.pivotColumns || []
this.onQueryHook = this.options.onQuery
this.meta = this.options.meta
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/types/relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type RelationOptions<
foreignKey?: string
serializeAs?: string | null
onQuery?(query: Related['builder'] | Related['subQuery']): void
meta?: any
}

/**
Expand All @@ -87,6 +88,7 @@ export type ManyToManyRelationOptions<Related extends ModelRelations<LucidModel,
}
serializeAs?: string | null
onQuery?(query: Related['builder'] | Related['subQuery']): void
meta?: any
}

/**
Expand All @@ -100,6 +102,7 @@ export type ThroughRelationOptions<
throughLocalKey?: string
throughForeignKey?: string
throughModel: () => LucidModel
meta?: any
}

/**
Expand Down
Loading