It doesn't works better, but I've noticed that if I use the fetch type 
EAGER for the associated entity, the values are retrieved, it seems a 
problem brought by proxies

Le mardi 14 octobre 2014 20:28:59 UTC+2, Holtkamp a écrit :
>
> Maybe remove the Event.userId property. You don't need it, try to think in 
> objects, not in identifiers / ids.
>
> Cheers
> On Oct 14, 2014 5:15 PM, "Giulio Provasi" <[email protected] <javascript:>> 
> wrote:
>
>> Hello, I have the following:
>>
>> *USER*
>>
>> <?php namespace Application\Model;
>>
>> use Doctrine\Common\Collections;
>> use Doctrine\ORM\Mapping as ORM;
>>
>> /**
>>  * User model
>>  * Read-only entity
>>  * @ORM\Table(name="VLOGGER_WEBCALENDAR_USR")
>>  * @ORM\Entity(readOnly=true)
>>  * @package Application\Model
>>  */
>> class User
>> {
>> /**
>>  * @var int
>>  * @ORM\Id
>>  * @ORM\Column(name="USR_ID", type="integer")
>>  */
>> protected $id;
>>
>> /**
>>  * @var string
>>  * @ORM\Column(name="USR_LOGIN", type="string")
>>  */
>> protected $login;
>>
>> /**
>>  * @var string
>>  * @ORM\Column(name="USR_CODE", type="string")
>>  */
>> protected $code;
>>
>> /**
>>  * @var int
>>  * @ORM\Column(name="GRP_ID", type="integer")
>>  */
>> protected $groupId;
>>
>> /**
>>  * @var string
>>  * @ORM\Column(name="GRP_CODE", type="string")
>>  */
>> protected $groupCode;
>>
>> /**
>>  * @var User\Group
>>  * 
>> @ORM\ManyToOne(targetEntity="Application\Model\User\Group",fetch="EAGER")
>>  * @ORM\JoinColumn(name="GRP_CODE", referencedColumnName="GRP_CODE")
>>  */
>> protected $group;
>>
>> /**
>>  * @var Collections\ArrayCollection
>>  * @ORM\OneToMany(targetEntity="Application\Model\Event", mappedBy="user")
>>  * @ORM\JoinColumn(name="USR_ID", referencedColumnName="USR_ID")
>>  */
>> protected $events;
>>
>> /**
>>  * Constructor
>>  */
>> public function __construct()
>> {
>> $this->events = new Collections\ArrayCollection();
>> }
>>  // accessors
>> }
>>
>> *EVENT*
>>
>> <?php namespace Application\Model;
>>
>> use Doctrine\ORM\Mapping as ORM;
>>
>> /**
>>  * Calendar event model
>>  * This model is readonly
>>  * @ORM\Table(name="VLOGGER_WEBCALENDAR")
>>  * @ORM\Entity(readOnly=true)
>>  * @package Application\Model
>>  */
>> class Event
>> {
>>
>> /**
>>  * @ORM\Id
>>  * @ORM\Column(name="LOG_ID", type="integer")
>>  */
>> protected $id;
>>
>> /** @ORM\Column(name="USR_ID", type="integer") */
>> protected $userId;
>>
>> /** @ORM\Column(name="DAY_TYPE", type="string") */
>> protected $type;
>>
>> /** @ORM\Column(name="FORMATTED_DAY", type="date") */
>> protected $date;
>>
>> /** @ORM\Column(name="DAY", type="string") */
>> protected $litteralDate;
>>
>> /** @ORM\Column(name="PI", type="boolean") */
>> protected $piquet;
>>
>> /** @ORM\Column(name="QUAND", type="string") */
>> protected $when;
>>
>> /** @ORM\Column(name="DAY_DES", type="string") */
>> protected $description;
>>
>> /**
>>  * @var User the user this events belongs
>>  * @ORM\ManyToOne(targetEntity="Application\Model\User", 
>> inversedBy="events")
>>  * @ORM\JoinColumn(name="USR_ID", referencedColumnName="USR_ID")
>>  */
>> protected $user;
>>
>> /**
>>  * @var Event\Writer Event data writer
>>  * @ORM\ManyToOne(targetEntity="Application\Model\Event\Writer", 
>> inversedBy="event")
>>  * @ORM\JoinColumn(name="LOG_ID", referencedColumnName="LOG_ID")
>>  */
>> protected $writer;
>>
>> // accessors
>> }
>>
>>
>>
>> And the following db:
>>
>> vlogger_calendar (the EVENT):
>> PI
>> QUAND
>> LOG_ID
>> USR_ID
>> USR_LOGIN
>> USR_CODE
>> YYWW
>> YYMM
>> YYYY
>> TDAYS_COUNTER
>> TVAC_COUNTER
>> DAY_TYPE
>> DD
>> DAY
>> FORMATTED_DAY
>> DAY_DES
>> GRP_ID
>> GRP_CODE
>>
>> and the user view:
>> USR_ID
>> USR_LOGIN
>> USR_CODE
>> GRP_ID
>> GRP_CODE
>>
>> The one to many relationship USER > EVENTS works great, but the EVENT > 
>> USER don't work (the object stay null)
>>
>> *Works:*
>> $usr = $em->find('Application\Model\User', 5);
>> var_dump($usr->getEvents()->toArray());
>>
>>
>> *Don't works:*
>> $evt = $em->find('Application\Model\Event', 4962);
>> var_dump($evt->getUser());
>>
>>
>>
>> Any idea ?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "doctrine-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/doctrine-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to