finish TreeModel implementation and updateMany builder method
This commit is contained in:
@@ -33,14 +33,24 @@ export abstract class HasOneOrMany<T extends Model<T>, T2 extends Model<T2>, V e
|
||||
return this.localKeyOverride || this.foreignKey
|
||||
}
|
||||
|
||||
public get foreignColumn(): string {
|
||||
const ctor = this.related.constructor as typeof Model
|
||||
return ctor.propertyToColumn(this.foreignKey)
|
||||
}
|
||||
|
||||
public get localColumn(): string {
|
||||
const ctor = this.related.constructor as typeof Model
|
||||
return ctor.propertyToColumn(this.localKey)
|
||||
}
|
||||
|
||||
/** Get the fully-qualified name of the foreign key. */
|
||||
public get qualifiedForeignKey(): string {
|
||||
return this.related.qualify(this.foreignKey)
|
||||
return this.related.qualify(this.foreignColumn)
|
||||
}
|
||||
|
||||
/** Get the fully-qualified name of the local key. */
|
||||
public get qualifiedLocalKey(): string {
|
||||
return this.related.qualify(this.localKey)
|
||||
return this.related.qualify(this.localColumn)
|
||||
}
|
||||
|
||||
/** Get the value of the pivot for this relation from the parent model. */
|
||||
@@ -70,11 +80,11 @@ export abstract class HasOneOrMany<T extends Model<T>, T2 extends Model<T2>, V e
|
||||
.all()
|
||||
|
||||
return this.related.query()
|
||||
.whereIn(this.foreignKey, keys)
|
||||
.whereIn(this.foreignColumn, keys)
|
||||
}
|
||||
|
||||
/** Given a collection of results, filter out those that are relevant to this relation. */
|
||||
public matchResults(possiblyRelated: Collection<T>): Collection<T> {
|
||||
return possiblyRelated.where(this.foreignKey as keyof T, '=', this.parentValue)
|
||||
return possiblyRelated.where(this.foreignColumn as keyof T, '=', this.parentValue)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user