Polymorphic class creating in Castle Project ActiveRecord
I am using ActiveRecord in order to store my classes in the database.
I have classes hierarchy, say it Man and Woman inherited from class Human. Human database table contains fie开发者_StackOverflow中文版ld Sex which is 0 for man and 1 for woman. I'd like to be able to load class Human with regards to Sex field, that is, if Sex is 0, loading of class Human should actually create instance of class Man (thus reading some additional fields from Man table besides of fields from Human table).
Is it possible with the help of CastleProject ActiveRecord attributes? If not, is it possible to do with overriding some overridable methods?
You are talking about Single Table Inheritance
The Sex column in your table will serve as the Discriminator used by NHibernate.
EDIT: If you have additional fields for Man, you can either put them in the one large table or split them out and use Class Table Inheritance (which means a JOIN whenever you fetch Men objects) since it gets the Human fields from the Human table and the Man fields from the Man table.
精彩评论