26

I'm using Doctrine 1.2 on a symfony project, and I'm considering mixing concrete and column aggregation inheritance types in my schema: column aggregation lets me query in a parent table and get both parent and child records, while concrete inheritance lets me get a cleaner schema. Plus, the mix will be in the same inheritance chain. How would I write the schema file? Like the following?

A:

B:
  inheritance:
    extends: A
    type: concrete

C:
  inheritance:
    extends: B
    type: column_aggregation
    keyField:         type
    keyValue:         1

Or like this perhaps:

A:

B:
  inheritance:
    extends: A
    type: concrete

C:
  inheritance:
    extends: B
    type: concrete
D:
  inheritance:
    extends: C
    type: column_aggregation
    keyField:         type
    keyValue:         1


E:
  inheritance:
    extends: C
    type: column_aggregation
    keyField:         type
    keyValue:         2

Are there any dangers/caveats ?

greg0ire
  • 22,714
  • 16
  • 72
  • 101
  • Looks like no one else has experience to share. I'd be interested to know how this went though - my initial thought was that it'd not work well. – benlumley Jan 14 '11 at 08:34
  • @benlumley Well, we've tried it, and we are testing, and it seems to work pretty well for the moment. I'll edit my post and add a comment if we encounter some problems though. We tried with the second version of the schema. – greg0ire Jan 14 '11 at 08:42
  • @greg0ire: BEWARE relations when concrete inheritance is involved :-) MAke sure you dont define them on the base table. Ive never mixed and matched to any extent either so ill be itnerested to hear of any issue you come across... – prodigitalson Jan 17 '11 at 09:26
  • 1
    @prodigitalson : could you elaborate? Why exactly is inherinting the relation dangerous? Because of the foreign aliases. I'll post here any issue I come across (including this one if it is one). – greg0ire Jan 17 '11 at 09:51
  • @greg0ire: Because with concrete inheritence the base table (`A`) is created but not used. If you have foreign keys that point to `A` the key check will fail because the data is actually stored in `B`. As long as you keep your relations on the aggregation tables you should be ok though. But in some some cases that kind of defeats the purpose of having `A` to begin with. – prodigitalson Jan 17 '11 at 10:07
  • @prodigitalson: Thank you for this clarification. We were aware that we could not retrieve all objects of a sub-type from the parent type table with concrete inheritance, but we hadn't thought about this relation problem. Luckily, we have no relations on the parent table, so everything is fine. – greg0ire Jan 17 '11 at 10:42

1 Answers1

1

As long as you avoid circular inheritance or diamond shaped inheritance you would be fine and can use this

A circular inheritance (obviously looks as follows

Class A Extends B Class B Extends A

OR

CLASS A EXTENDS C

CLASS B EXTENDS A

CLASS C EXTENDS A

A Diamond Shaped inheritance is a bit more round about. It happens when the following type of condition happens

CLASS A

CLASS B EXTENDS A

CLASS C EXTENDS A

CLASS D EXTENDS B,C

footy
  • 5,803
  • 13
  • 48
  • 96
  • Are you saying multiple inheritance is possible with doctrine? Since it is not with php, I doubt it... +1 for the vocabulary though – greg0ire Apr 30 '11 at 16:43
  • All i am trying to say is as long as these constrains are not there. We can safely do inheritance. – footy Apr 30 '11 at 17:04