2
2 개의 엔티티가 있습니다 : ProfileContact 및 Profile. 그들 사이에는 연관성이 있습니다.Doctrine2 - 연관된 엔티티를 가져 오지 않고 접속이있는 엔티티를 유지합니다.
class ProfileContact {
/**
* @var integer $profileContactId
*
* @ORM\Column(name="profile_contact_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $profileContactId;
/**
* @var text $description
*
* @ORM\Column(name="description", type="text",
* nullable=true)
*/
private $description;
/**
* @var Profile
*
* @ORM\ManyToOne(targetEntity="Profile")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="profile_id",
* nullable=false,
* onDelete="CASCADE", referencedColumnName="profile_id")
* })
*/
private $profile;
}
.
물론 적절한 설정자와 게터가 있습니다.
ProfileContact 엔티티를 기존 프로필과 연결하여 생성하고 지속해야하지만 이전에 D2에서 가져 오지 않는 방법은 무엇입니까? 나는 전체 프로필 엔티티에 대해 데이터베이스에 묻고 싶지 않습니다.
$profile = $this->getProfileRepository()->find(2); //I want to avoid this
$item = new \Alden\BonBundle\Entity\ProfileContact();
$item->setProfile($profile);
$item->setDescription('abc');
$em = $this->getEntityManager();
$em->persist($item);
$em->flush();