gorm - inheritance in Grails domain model -


my grails app's domain model has following requirements:

  • a user belong 0 or 1 organisations
  • an organisation either charity or company
  • charities , companies have some common fields , (non-nullable) fields unique each organisation type

i put common organisation fields abstract organisation class charity , company both extend. can't store hierarchy in single table because there non-nullable fields specific each organisation type. relevant parts of domain model shown below:

class user {   string name    static belongsto = [organization: organization]    static constraints = {     organization nullable: true   } }  abstract class organization {         string name      static hasmany = [users: user]      static mapping = {         tableperhierarchy false     } }  class charity extends organization {   // charity-specific fields go here }   class company extends organization {   // company-specific fields go here } 

when @ mysql schema generated model, inheritance relationship between organisation-company , organisation-charity seems have been ignored. although there organisation table name column, has no primary-foreign key relationship either company or charity

  1. i see same result ianroberts both mysql , h2. in other words: no join table generated, expected organization_id fk in users table.
  2. with "table per subclass" mapping (tableperhierarchy false), end implied one-to-one relationship in database. primary keys charity , company have same value pk parent organization. schema generated gorm/hibernate3 doesn't appear enforce referential integrity constraints. it's pure hibernate magic. bit more detail here

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -