🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.php
Article #230806

doctrine2 - findall i @OneToOne

#230806
From: Replay
Date: Sun, 21 Dec 2014 17:23
142 lines
3697 bytes
Witam,

utworzyłem sobie takie dwie proste encje:


/**
 * @Entity
 *
@Table(name="sys_users",uniqueConstraints={@UniqueConstraint(name="login_idx",
columns={"login"}),@UniqueConstraint(name="email_idx", columns={"email"})})
 * */
class SysUser extends Base{


    /**
     * @Column(type="text", nullable=false)
     */
    public $login;

    /**
     * @Column(type="text", nullable=false)
     */
    public $passwd;


    /**
     * @Column(type="text", nullable=false)
     */
    public $email;

    /**
     * @Column(type="text", nullable=false, options={"default" = "USER"})
     */
    public $rola;

    /**
     * @Column(type="integer", nullable=true,options={"default" = -1})
     */
    public $fkstatuspm;

    /**
     * @Column(type="datetime", nullable=true)
     */
    public $dtstatus;

    /**
     * @OneToOne(targetEntity="OsOsoba")
     * @JoinColumn(name="fk_osobapm", referencedColumnName="pm")
     */
    public $osOsoba;

    public function getOsoba(){
    	return $this->osOsoba;
    }


}


/**
 * @Entity
 * @Table(name="os_osoby")
 */
class OsOsoba extends Base {
	
	/**
	 * @Column(type="text", nullable=false)
	 */
	public $imie;
	
	/**
	 * @Column(type="text", nullable=false)
	 */
	public $nazwisko;
	
	/**
	 * @Column(type="integer", nullable=false)
	 */
	public $fkprzelozonypm;
	
	//
	public function getOsobaName() {
		return $this->nazwisko . " " . $this->imie;
	}
}



Zapisałem do bazy dane:

        $osoba = new \app\libs\Entity\OsOsoba ();
        $osoba->nazwisko = "Kowalski";
        $osoba->imie = "Jan";
        $osoba->fkprzelozonypm = - 1;

        $user = new \app\libs\Entity\SysUser ();
        $user->login = "maciej";
        $user->passwd = md5 ( "1" );
        $user->email = "jk@mail.com";
        $user->rola = "001";
        $user->dtstatus = new DateTime ();
        $user->osOsoba = $osoba;

        $em->persist ( $user );
        $em->persist ( $osoba );
        $em->flush ();



        $osoba = new \app\libs\Entity\OsOsoba ();
        $osoba->nazwisko = "Kowalski";
        $osoba->imie = "Andrzej";
        $osoba->fkprzelozonypm = - 1;

        $user = new \app\libs\Entity\SysUser ();
        $user->login = "maciej";
        $user->passwd = md5 ( "1" );
        $user->email = "ak@mail.com";
        $user->rola = "099";
        $user->dtstatus = new DateTime ();
        $user->osOsoba = $osoba;

        $em->persist ( $user );
        $em->persist ( $osoba );
        $em->flush ();


I teraz gdy chce pobrać dane w taki oto sposób (osobny skrypt):

$repo = $em->getRepository('app\libs\Entity\SysUser');
try {
        $q = $repo->findAll();
}

var_dump($q);

Skrypt się zapętla i kończy pracę (chce więcej pamięci niż może)...

Czy ktoś może mnie naprowadzić co robię w niewłaściwy sposób?


Dziękuję za pomoc :D
Technical Details
Message-ID: <m76vlq$84q$1@news.icm.edu.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!.POSTED!not-for-mail
From: Replay <replay111@o2.pl>
Newsgroups: pl.comp.lang.php
Subject: doctrine2 - findall i @OneToOne
Date: Sun, 21 Dec 2014 18:23:06 +0100
Organization: ICM, Uniwersytet Warszawski
Lines: 143
Message-ID: <m76vlq$84q$1@news.icm.edu.pl>
NNTP-Posting-Host: 245.85-237-170.tkchopin.pl
Mime-Version: 1.0
X-Trace: news.icm.edu.pl 1419182586 8346 85.237.170.245 (21 Dec 2014 17:23:06 GMT)
X-Complaints-To: usenet@news.icm.edu.pl
NNTP-Posting-Date: Sun, 21 Dec 2014 17:23:06 +0000 (UTC)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit