You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone,
I'm having a piece of code that implements the template method pattern.
So I have an abstract base class that needs its child classes to provide an implementation. This concrete implementation should return either a DatabaseQueryBuilderContract or a ModelQueryBuilderContract<typeof T, T>.
To be more specific I want to get the result of something like that for example:
return User.query().where('last_active', '<', DateTime.local().minus({ days: 10 }).
This is the code I came up with:
Base class:
import{DatabaseQueryBuilderContract}from'@ioc:Adonis/Lucid/Database'import{LucidModel,ModelQueryBuilderContract}from'@ioc:Adonis/Lucid/Orm'import{DateTime}from'luxon'exportdefaultabstractclassMyBaseClass<TextendsLucidModel>{publicasyncdeleteExpired(): {constdeletedValues=awaitthis.getExpiredValues().delete()}/** * Define which values in the table need to be deleted. Use the Lucid DatabaseQueryBuilderContract<any> or ModelQueryBuilderContract<T, T> to return the query */protectedabstractgetExpiredValues(): DatabaseQueryBuilderContract<any>|ModelQueryBuilderContract<T,T>}
import{DateTime}from'luxon'import{column,BaseModel}from'@ioc:Adonis/Lucid/Orm'exportdefaultclassUserextendsBaseModel{
@column({isPrimary: true})publicid: number
@column()publicfirstName: string
@column()publiclastName: string
@column.dateTime()publiclastActive: DateTime}
The error I'm facing occurs in the implementation class 'MyChildClass': Type 'User' does not satisfy the constraint 'LucidModel'.
Type 'User' is missing the following properties from type 'LucidModel': booted, $columnsDefinitions, $relationsDefinitions, $computedDefinitions, and 40 more.
How can I solve this problem? Any help is really appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I'm having a piece of code that implements the template method pattern.
So I have an abstract base class that needs its child classes to provide an implementation. This concrete implementation should return either a DatabaseQueryBuilderContract or a ModelQueryBuilderContract<typeof T, T>.
To be more specific I want to get the result of something like that for example:
return User.query().where('last_active', '<', DateTime.local().minus({ days: 10 }).
This is the code I came up with:
Base class:
And this is one implementation:
User class:
The error I'm facing occurs in the implementation class 'MyChildClass': Type 'User' does not satisfy the constraint 'LucidModel'.
Type 'User' is missing the following properties from type 'LucidModel': booted, $columnsDefinitions, $relationsDefinitions, $computedDefinitions, and 40 more.
How can I solve this problem? Any help is really appreciated!
Beta Was this translation helpful? Give feedback.
All reactions