Currently, I am utilizing https://github.com/bashleigh/typeorm-polymorphic for handling polymorphic relations in my model. There are several models involved:
// Device Entity
@Entity()
@TableInheritance({ column: { type: 'varchar', name: 'type' } })
export class Device extends BaseModel { // Base model consists of primary generated id and timestamp
// Device specific code here
}
// Lock entity
@ChildEntity()
export class Lock extends Device {
// Lock specific code here
@PolymorphicChildren(()=>ConnectionData, {
eager: false
})
providers: ConnectionData[]
}
// Connection Data entity
@Entity()
@TableInheritance({ column: { type: 'varchar', name: 'type' } })
export class ConnectionData extends BaseModel {
// Basic connection data functionality
}
// First User Type entity
@ChildEntity()
export class FirstUserType extends ConnectionData implements PolymorphicChildInterface {
// Additional First User Type properties
@PolymorphicParent(()=>[Lock,Key]) // Key is also a parent similar to lock
connectable: Lock | Key
@Column({name: 'connectableId'})
entityId: string;
@Column({name: 'connectableType'})
entityType: string;
}
By implementing the following code snippet:
let repo = connection.getCustomRepository(FirstUserTypeRepository) // extends AbstractPolymorphicRepository
let result = repo.findOne(1) // fetching data based on an ID
I am able to retrieve the aforementioned data. However, I aim to achieve a different output:
{
id: // represents first user type ID
prop: // other properties related to first user type
connectable : {
// Lock object information
}
}
My desired output structure should look like this:
{
id: // some lock ID
data: // additional lock data
providers: [
// List of ConnectionData entities should be included here
]
}
In an attempt to accomplish this, I crafted a script that I believed would fulfill the requirement:
let repo = connection.getCustomRepository(LockRepository) // extends AbstractPolymorphicRepository
let result = repo.findOne(1) // searching for a lock by its ID
However, when executing the above code, the following error occurred:
TypeORMError: Function parameter isn't supported in the parameters. Please check "orm_param_1" parameter.
I have been investing time and effort over the past few days to resolve this issue, but unfortunately, I have not yet managed to find a solution.