B
B
BonBon Slick2021-02-28 00:30:17
Doctrine ORM
BonBon Slick, 2021-02-28 00:30:17

Combined oneToMany relationships User->RelationCollection[ApiTokenCollection, ResetPassCollection]?

class User implements UserInterface, IAggregateRoot {
    public ActivationTokenCollection                   $activationTokens;
    public ApiTokenCollection                          $apiTokens;
    public ResetPasswordTokenCollection                 $resetPassTokens;
// other tokens...


How to build a mapping what would happen
class User implements UserInterface, IAggregateRoot {
    public TokensCollections                   $tokens;
// other tokens...

public function getTokens(){
// output ArrayCollection->toArray() ---> [ActivationTokenCollection, ApiTokenCollection, ResetPasswordTokenCollection]
}

public function getApiTokens(){
// output ArrayCollection->toArray() [ApiTokenCollection]
}

Different tokens have some other fields, all of which come from the main Abstract token, of course.
This can be done with other entities, for example, the user has a bunch of files of different types.
Sculpting a collection for each file type is not an option.
A user can have multiple links of multiple links.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2021-02-28
@BonBonSlick

If I understand your question correctly, then you can make the AbstractTokenbase entity for inheritance mapping , and inherit other types of tokens from it, defining them in @DiscriminatorMap.
Then, if somewhere you need to get a list of only a certain type of tokens, it will be enough in the definition, for example, @OneToManyto specify targetEntitythe entity class you need, and if all the tokens are needed, then you can specifyAbstractToken

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question