Replies: 5 comments 3 replies
-
Try out the following code, I think it'll achieve what you were looking for: import { Entity, Fields } from 'remult'
@Entity('people', {
allowApiCrud: true,
})
export class Person {
@Fields.cuid()
id = ''
@Fields.string()
name = ''
@Fields.string({ allowApiUpdate:false })
discr = ''
}
@Entity<Person>('employees', {
allowApiCrud: true,
dbName: 'people',
backendPrefilter: {
discr: 'person',
},
saving: (self) => {
self.discr = 'person'
},
})
export class Employee extends Person {} On the I've added a Let me know what you think |
Beta Was this translation helpful? Give feedback.
-
Yes, it should work, maybe you can also add a |
Beta Was this translation helpful? Give feedback.
-
It would be great to retrieve the instances of the corresponding discriminator value rather than the type used in the query. The following code retrieves Person instances rather than the instance indicated by the discr. That is forcing me to query the database again and again using the right type every time.
Another problem that I'm facing here is that Person cannot be abstract. Also, when using constructors the value of discr is wrongly set. It looks like the discr assignation is based on attribute matching rather than the type provided in the insert. Ex:
When having a constructor in Customer and Person, discr take the value of "person". I think because it is Person who has the attributes firstName and lastName, but the provided type was Customer, I expect the discr take "customer" value. Or the constructor is messing up something. |
Beta Was this translation helpful? Give feedback.
-
@noam-honig a couple of potential bugs here |
Beta Was this translation helpful? Give feedback.
-
When you use You can create follow up code that'll load the specific instance based on the As for the second issue you've mentioned with customer - I didn't exactly understand the issue - please add a code sample |
Beta Was this translation helpful? Give feedback.
-
Hello @noam-honig, I'm wondering if there a way to do something similar to what is done in Doctrine ORM for the Single Table Inheritance pattern?
Beta Was this translation helpful? Give feedback.
All reactions