Search code examples
phpneo4jneo4jphp

Add properties to relationships in a neo4j database using neo4j-OGM in PHP


while we are able to create new nodes etc., we are still struggling to find out how properties can be added to existing relationships. For instance we are declaring the following in an Entity format:

   /**
     * @OGM\ManyToMany(relation="GOES_TO_MARKET")
     */
    protected $shoppers;

How do we make it so that we can add additional properties to GOES_TO_MARKET using doctrine format?

Thanks


Solution

  • There is no direct way to do it through the API at this time. While there is some work in progress, it is quite far from completed.

    You can register a callback on relation creation.

    $em->registerEvent(HireVoice\Neo4j\EntityManager::RELATION_CREATE, function ($type, $relationName, $from, $to, $relation) {
        // $relation is the Everyman\Neo4j\Relationship
        if ($relationName === 'GOES_TO_MARKET') {
            $relation->setProperty('foobar', 'baz')->save();
        }
    });