Skip to content

Commit

Permalink
feat: add meta to all relations
Browse files Browse the repository at this point in the history
  • Loading branch information
zaosoula committed Jul 17, 2024
1 parent 2d25ef0 commit 643cd1d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
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

0 comments on commit 643cd1d

Please sign in to comment.