You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
841 B

import {Model} from '../Model.ts'
export function Relation(): MethodDecorator {
return (target: any, propertyKey, descriptor) => {
console.log('relation decorator', target, propertyKey, descriptor)
// @ts-ignore
const original = descriptor.value
// @ts-ignore
descriptor.value = function(...args) {
const model = this as Model<any>
const cache = model.relation_cache
const existing_relation = cache.firstWhere('accessor_name', '=', propertyKey)
if ( existing_relation ) return existing_relation.relation
// @ts-ignore
const value = original.apply(this, args)
cache.push({
accessor_name: propertyKey,
relation: value,
})
return value
}
}
}