Answer the question
In order to leave comments, you need to log in
One to many for super class mapping?
Docs
I know that
A mapped superclass cannot be an entity, it is not query-able and persistent relationships defined by a mapped superclass must be unidirectional (with an owning side only). This means that One-To-Many associations are not possible on a mapped superclass at all
protected ArrayCollection $apiCalls;
<mapped-superclass name="App\Domain\TokenPack\Shared\Entity\AbstractToken">
<embedded name="id"
class="App\Domain\Core\ValueObjects\EntityId"
use-column-prefix="false"
/>
...
<!-- One To Many -->
<one-to-many target-entity="App\Domain\LogPack\ApiCallLog\Entity\ApiCallLog"
field="apiCalls"
orphan-removal="true">
<cascade>
<cascade-persist/>
</cascade>
<order-by>
<order-by-field name="createdAt" direction="DESC"/>
</order-by>
</one-to-many>
<one-to-many target-entity="App\Domain\LogPack\ApiCallLog\Entity\ApiCallLog"
Answer the question
In order to leave comments, you need to log in
Temporary solution , it should be reviewed and tested more thoroughly.
class ApiCallLog implements IAggregateRoot {
public ?AuthToken $authToken;
public ?AnonToken $anonToken;
/**
* @throws Exception
*/
public function __construct(ApiCallLogCreateDTO $dto) {
if (null === $dto->anonToken && null === $dto->authToken) {
throw new Exception('One of tokens required to create entity');
}
...
public function token(): AbstractToken {
return true === $this->authToken instanceof AuthToken ? $this->authToken : $this->anonToken;
}
<entity name="App\Domain\TokenPack\Auth\Entity\AuthToken">
...
<!-- One To Many -->
<one-to-many target-entity="App\Domain\LogPack\ApiCallLog\Entity\ApiCallLog"
field="apiCalls"
mapped-by="authToken"
orphan-removal="true">
<cascade>
<cascade-persist/>
</cascade>
<order-by>
<order-by-field name="createdAt" direction="DESC"/>
</order-by>
</one-to-many>
field="anonToken"
mapping field.<entity name="App\Domain\LogPack\ApiCallLog\Entity\ApiCallLog"
repository-class="App\Infrastructure\Persistence\Repository\DB\DQL\ApiCallLog\DQLRepositoryApiCallLog">
....
<many-to-one target-entity="App\Domain\TokenPack\Auth\Entity\AuthToken"
field="authToken"
inversed-by="apiCalls"
>
<cascade>
<cascade-persist/>
</cascade>
<join-column name="auth_token_uuid" referenced-column-name="uuid" nullable="true"/>
</many-to-one>
<many-to-one target-entity="App\Domain\TokenPack\Anon\Entity\AnonToken"
field="anonToken"
inversed-by="apiCalls"
>
<cascade>
<cascade-persist/>
</cascade>
<join-column name="anon_token_uuid" referenced-column-name="uuid" nullable="true"/>
</many-to-one>
$apiCall->token() !== null
or WHERE authToken IS NOT NULL...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question