GraphAware\Neo4j\OGM\Persister\EntityPersister::getCreateQuery PHP Method

getCreateQuery() public method

public getCreateQuery ( $object )
    public function getCreateQuery($object)
    {
        $propertyValues = [];
        $extraLabels = [];
        $removeLabels = [];
        foreach ($this->classMetadata->getPropertiesMetadata() as $field => $meta) {
            $propertyValues[$field] = $meta->getValue($object);
        }
        foreach ($this->classMetadata->getLabeledProperties() as $labeledProperty) {
            if ($labeledProperty->isLabelSet($object)) {
                $extraLabels[] = $labeledProperty->getLabelName();
            } else {
                $removeLabels[] = $labeledProperty->getLabelName();
            }
        }
        $query = sprintf('CREATE (n:%s) SET n += {properties}', $this->classMetadata->getLabel());
        if (!empty($extraLabels)) {
            foreach ($extraLabels as $label) {
                $query .= ' SET n:' . $label;
            }
        }
        if (!empty($removeLabels)) {
            foreach ($removeLabels as $label) {
                $query .= ' REMOVE n:' . $label;
            }
        }
        $query .= ' RETURN id(n) as id';
        return Statement::create($query, ['properties' => $propertyValues], spl_object_hash($object));
    }