Where is document of Extends a model

I have 2 classes:
Class A extends DataObject
Class B extends Class A
But I couldn’t find out the document about this case on Silverstripe website, how Class B will work ?
Can anyone help to share the document about it ?

Class B will work as any PHP class would when it extends another. It will inherit the public / protected methods and properties, etc.

The PHP documentation will describe the general idea: PHP: Object Inheritance - Manual

Is there something specific you want to achieve, or something specific to dataobject inheritance you’re looking to discover?

Hi @Tim
Normal inheritance is not problem here mate :slight_smile:
My concern is:

  • What properties will we get when use model B ? Does it contains model A properties (was declared in private static $db = []) or not ? Because they are not public/protected so made me confused.
  • Model A is mapped to table A, Model B is mapped to table B. So when B extends A, then which columns will appear in table B, only private static $db = [] is declared in class B, right ? Is there any special column will appear in table B: ID ?
  • If later, I declare relation is: B has many A, so then what will happen ?

OK, so, dealing specifically with DataObject (and sub-classes)… those statics are all in the config system and are merged with their parents.

So, for example:

Class A has:

private static $db = [
  'Title' => 'Varchar'

Class B (which extends Class A) has the following:

private static $db = [
  'AnotherTitle' => 'Varchar'

Because the configs are merged, you effectively end up with the Class B db looking like this (even though you don’t actually have to code it this way):

private static $db = [
  'Title' => 'Varchar'
  'AnotherTitle' => 'Varchar'

So… in Class A you have access to the Title property of Class A. In Class B, you have access to the Title property of Class B, and also the AnotherTItle property of Class B.

1 Like

These are the docs which may cover what you’re after:

Thank you so much for your explanation!

I tried this docs before and couldn’t find out information relate to extends DataObject :slight_smile: