2016-10-11 2 views
0

Extbase에서 DB에 두 번째 필드를 추가하지 않고도 1 : 1 관계를 역으로 변환 할 수 있습니까?TYPO3 Extbase : InversedBy 1 : 1 관계

예 : 확장 프로그램에는 fe_user를 가질 수있는 담당자가 있습니다. Contact-Person-Domain-Model은 관계의 소유 사이트입니다.

Domain-Model

지금 당신은 DB에 추가하지 않고 FrontendUser에 반전 속성을 추가 할 수있는 방법이 있나요 $contactPerson->getFrontendUser();

사용할 수 있습니까?
$frontendUser->getContactPerson(),
또는 더 중요한 것은 $frontendUserRepository->findByContactPerson()입니다.

/** 
* FrontendUser 
*/ 
class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser 
{ 

    /** 
    * @var \Vendor\ExtKey\Domain\Model\ContactPerson 
    */ 
    protected $contactPerson = null; 
} 

그리고 fe_users의 TCA 오버라이드 (override) :


은 내가 FrontendUser-모델에 속성을 추가하는 시도

$GLOBALS['TCA']['fe_users']['columns']['contact_person'] = array(
    'exclude' => 1, 
    'label' => 'LLL:EXT:ExtKey/Resources/Private/Language/locallang_db.xlf:tx_ExtKey_domain_model_contactperson', 
    'config' => array(
     'type' => 'inline', 
     'foreign_table' => 'tx_ExtKey_domain_model_contactperson', 
     'foreign_field' => 'frontend_user', 
     'minitems' => 0, 
     'maxitems' => 1, 
    ), 
); 

을하지만 호출 할 때 :

/** 
* The repository for Customers 
*/ 
class FrontendUserRepository extends \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository 
{ 
    /** 
    * @param \Vendor\ExtKey\Domain\Model\ContactPerson $contactPerson 
    * @param boolean $ignoreEnableFields 
    * @param boolean $respectStoragePage 
    * @return object 
    */ 
    public function findByContactPerson(ContactPerson $contactPerson, $ignoreEnableFields = false, $respectStoragePage = true){ 
     $query = $this->createQuery(); 
     $query->getQuerySettings() 
      ->setIgnoreEnableFields($ignoreEnableFields) 
      ->setRespectStoragePage($respectStoragePage); 

     $query->matching($query->equals('contactPerson', $contactPerson)); 
     return $query->execute()->getFirst(); 
    } 
} 

다음과 같은 SQL-Error를 생성합니다 :

Unknown column 'fe_users.contact_person' in 'where clause'

답변

2

계산 된 양방향 1 : 1 관계는 TYPO3 만 m에서 지원되지 않는다 : N의 관계를 지원하는 추가 definition in TCA 함께 - 관계도의 대향 위치에 추가 필드를 필요로한다.

시나리오와 관련하여 확장 된 FrontendUser 도메인 모델에서 추가 속성 및 데이터베이스 필드를 직접 만들어야합니다.