Hello,
I have a problem with class inheritance and repository using Postgre SQL.
Let's say we have Animal parent class and then Dog and Chicken child classes. I store them in one table (Table Per Hierarchy Inheritance) called animal.
In LB4 App I have Animal base model (entityType is a discriminator):
@model({
settings: {
postgresql: {
table: 'animal',
},
idInjection: false,
strict: false,
},
})
export class Animal extends Entity {
@property({
type: 'string',
id: true,
postgresql: {
dataType: 'uuid',
},
})
id: string;
@property({
type: 'string',
required: true,
})
entityType: string;
@property({
type: 'number',
required: true,
})
weight: number;
@hasMany(() => Zookeeper)
zookepers?: Zookeeper[];
constructor(data?: Partial<Animal>) {
super(data);
}
}
and child class dog
@model()
export class Dog extends Animal {
@property({
type: 'number',
required: true
})
barkingLevel: number;
constructor(data?: Partial<Dog>) {
super(data);
}
}
When I query a dog from the repository barkingLevel is ommited on output though the strict is set to false.
This will return animal (not a dog) without barkingLevel .
const dog : Dog = await this.animalRepository.findById(id, {
include: [
{ relation: 'zookepers' }
],
}) as Dog;
Repository:
export class AnimalRepository extends DefaultCrudRepository<
Animal,
typeof Animal.prototype.id
> {
//declare has-many repositories for related zookeeper entities
public readonly zookeepers: HasManyRepositoryFactory<
Zookeeper,
typeof Zookeeper.prototype.id
>;
....
Expected result: Returned animal from repository should include extra properties from dog since the strict setting is set to false.
Current result: Only properties belonging to parent class are returned.
NOTE: If I do the same thing in Mongo DB, everything works as expected.
Thank you.
Acceptance criteria
See #4042 (comment)
At the moment, the data is discarded silently, the framework does not print any warnings about unsupported strict value used with a SQL connector. Personally, I'd like the framework to detect this scenario and print a warning (once for each model), so that developers have easier time troubleshooting the unexpected behavior.
Hello,
I have a problem with class inheritance and repository using Postgre SQL.
Let's say we have Animal parent class and then Dog and Chicken child classes. I store them in one table (Table Per Hierarchy Inheritance) called animal.
In LB4 App I have Animal base model (entityType is a discriminator):
and child class dog
When I query a dog from the repository barkingLevel is ommited on output though the strict is set to false.
This will return animal (not a dog) without barkingLevel .
Repository:
Expected result: Returned animal from repository should include extra properties from dog since the strict setting is set to false.
Current result: Only properties belonging to parent class are returned.
NOTE: If I do the same thing in Mongo DB, everything works as expected.
Thank you.
Acceptance criteria
See #4042 (comment)