graphaware / neo4j-php-ogm

Neo4j Object Graph Mapper for PHP
MIT License
153 stars 55 forks source link

Inheritance Problem #114

Open vladrolandomihai opened 7 years ago

vladrolandomihai commented 7 years ago

Hello.

I have the following model:

abstract class Accessory {
   protected $name; //+getter and setters
   protected $photol; //+getter and setters
}

class Light extends Accessory {
   protected $on; //+getter and setters
}

class BrightnessLight extends Light {
   protected $brightness; //+getter and setters
}

class ColorLight extends BrgithnessLight {
  protected $red; //+getter and setters
  protected $green; //+getter and setters
  protected $blue; //+getter and setters
}

Now if I query the neo4j database for a color light accessory I receive the following object:

TestController.php on line 46:
neo4j_ogm_proxy_AppBundle_Entity_Accessory_Accessory {#561
  -em: null
  -initialized: []
  -initializers: []
  -node: GraphAware\Neo4j\Client\Formatter\Type\Node {#575
    #id: 75
    #labels: array:4 [
      0 => "Accessory"
      1 => "Light"
      2 => "BrightnessLight"
      3 => "ColorLight"
    ]
    #properties: array:7 [
      "red" => 0
      "green" => 0
      "brightness" => 95
      "blue" => 255
      "name" => "Color Light"
      "photo" => ""
      "on" => true
    ]
  }
  #id: 75
  #name: "Color Light"
  #photo: ""
}

As you can see I have 4 labels set on my color light: Accessory, Light, BrightnessLight, ColorLight.

I am able to call getId(), getName(), and getPhoto() on the object, however I cannot call getBrightness(), getRed(), getGreen() and getBlue().

Does the OGM support class inheritance yet ?

ikwattro commented 7 years ago

Hi @vladrolandomihai Thanks for the report. The OGM doesn't support inheritance (also in Doctrine inheritance is to avoid). I understand the use case though and will add basic support in the next RC's. Now working with a graph inheritance is rarely managed by labels but more with relationships (which is supported)