douhuan1950 2015-10-30 17:51
浏览 33

如何做一个ManytoMany或ManyToOne Doctrine Neo4j

I'm learning how to work with Neo4j and Doctrine OGM, and I'm having problems with my source code. I don't know how to use manytomany because I'm just starting learn. When I save I see:

Catchable fatal error: Argument 1 passed to Entity\Empresas::setTelefone() must be an instance of Entity\Entity\Telefones, string given, called in /Applications/MAMP/htdocs/neo4j/n4j/save.php on line 17 and defined in /Applications/MAMP/htdocs/neo4j/n4j/Empresas.php on line 50

My Empresas.php entity

namespace Entity;

use HireVoice\Neo4j\Annotation as OGM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * All entity classes must be declared as such.
 *
 * @OGM\Entity(labels="Empresas")
 */
class Empresas
{
    /**
     * The internal node ID from Neo4j must be stored. Thus an Auto field is required
     * @OGM\Auto
     */
    protected $id;

    /**
     * @OGM\Property
     * @OGM\Index
     */
    protected $nome;

    /**
     * @OGM\Property
     */
    protected $keywords;

    /**
     * @OGM\ManyToOne(relation="tem_telefone")
     */
    protected $telefone;


    function getID(){
        return $this->id;
    }
    function setNome($nome){
        $this->nome = $nome;
    }
     function setKeywords($keywords){
        $this->keywords = $keywords;
    }

    public function getTelefone() {
         return $this->telefone;
    }
    public function setTelefone(Entity\Telefones $telefone) {
        $this->telefone = $telefone;
    }
}`

My Telefones.php Entity

    <?php
namespace Entity;

use HireVoice\Neo4j\Annotation as OGM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * All entity classes must be declared as such.
 *
 * @OGM\Entity(labels="Empresas")
 */
class Telefones
{
    /**
     * The internal node ID from Neo4j must be stored. Thus an Auto field is required
     * @OGM\Auto
     */
    protected $id;

    /**
     * @OGM\Property
     * @OGM\Index
     */
    protected $telefone;



    function getID(){
        return $this->id;
    }

}

And my Save.php Entity

    <?php

require 'bootstrap.php';
require 'Empresas.php';
require 'Telefones.php';

$repo = $em->getRepository('Entity\\Empresas');

$empresa_container = $em->find('Entity\\Empresas', "22");
$telefones = new Entity\Telefones();



$empresa = new Entity\Empresas;
$empresa->setNome("nome");
$empresa->setKeywords("keywords");
$empresa->setTelefone("telefone");

$em->persist($telefones);
$em->persist($empresa);
$em->flush();
echo $empresa->getId();

Error

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow