how to represent supertype/subtype?

Asked by Cuong

Hi,

I have 3 classes: PERSON (supertype) and 2 subtypes: STUDENT, TEACHER
In OpenERP, we can use inheritance for STUDENT and TEACHER. This will introduce foreign key (named person_id) in STUDENT, TEACHER tables. I create a view for PERSON. I want to edit/display all attributes of STUDENT or TEACHER in PERSON view.

In case of disjoint/overlap between supertype and subtype, how can we solve it?

Thanks,

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Cuong
Solved:
Last query:
Last reply:
Revision history for this message
Numérigraphe (numerigraphe) said :
#1

I humbly advise you to not use inheritance for this: that's not what it's for in OpenERP.
Put all the fields to the class "person" and conditionally show/hide the fields of person.
Lionel Sausin.

Revision history for this message
Cuong (bhcuong2008) said :
#2

Hi Lionel,

With several attributes, we can do this. But with many attributes, it will result many NULL values. It will be inefficient. And in case of having many levels of subtype such as PERSON -> STUDENT -> GRADUATE STUDENT.

My head is broken when thinking of how to represent supertype/subtype in OpenERP :(

Revision history for this message
James Jesudason (jamesj) said :
#3

You can able to use a 'Person' model to represent all of these types of people, and show/hide the fields that you need based on a 'type' field. This is the simplest approach and will probably be fine.

If you need to lock down security and have completely different access rules for a person vs student vs graduate, then you can use inheritance using the '_inherits' attribute (note the 's' on the end). An example of this is in the 'hr' where hr.employee '_inherits' resource.resource. I doubt that you will need to take this approach in your situation.

Revision history for this message
Pieter J. Kersten (EduSense BV) (pieterj) said :
#4

You could model the two concepts as roles for persons. It will also allow you to handle the (real world) situation where a person is both.

Revision history for this message
Numérigraphe (numerigraphe) said :
#5

"My head is broken when thinking of how to represent supertype/subtype in
OpenERP :("
That's because you're thinking object-oriented, but OpenERP is not that. The framwork is firmly tied to an RDBMS.
That's how the ORM is so simple compared to EJB3 or Hibernate.

so keep thinking OO, but code relational and do the "mapping" yourself.
It's a classic OO problem and it boils down to:
- either add all the fields to the table and accept lots of NULL => use _inherit
- either move the subtypes to dedicated tables, and use EITHER the supertype OR one subtype but NOT both in the same time => use _inherits
- either give up your subtype/supertype relationship for an aggregation => use one2many, I think that's Pieter J. Kersten's idea
Lionel Sausin.

Revision history for this message
Numérigraphe (numerigraphe) said :
#6

Or if you're bold enough, you can experiment with Postgres's OO features, there are probably interresting things to do with that but the framework may require subtle adjustments.
If you do, please let the framework experts know about your progress (they have a mailing list and a LP team) - I think it can be interesting.
Lionel.

Revision history for this message
Cuong (bhcuong2008) said :
#7

Thank you for all your comments. Integrate subtypes into supertype may be the best solution right now.

Hope that OpenERP framework team can support PostgreSQL's OO feature.