php - TYPO3: How to implement a virtual attribute based on a relationship table? ← (PHP)

one text

My question is simpler to what the title suggests, it's the most succinct way I've managed to word it...

What I want to do is: My Project entity is linked to User through a MM table. At the same time, Users are linked to multiple Companies. In the project-user-mm table, I've added a field called user_company, which stores a reference to the User's Company through which they are involved with the Project.

I think that this reference to the Company belongs in the Project-User relationship table instead of to the Project table directly because the Project-Company relationship is implicit through the User. Am I correct?

What I want to achive is that at the higher level (Extbase), whenever I call Project->getCompanies, it fetches all the companies: each company from each project-user-mm table. I don't need any other method (e.g. set, add, remove, ...), since it wouldn't make sense to use them, because the Companies are retrieved implicitly from the relationships with the Users.

What would be the most idiomatic way to do this with TYPO3?

  • In the Project Model: Besides the getCompanies method, do I need a companies attribute?
  • In the Project TCA: do I need a companies column? In the case that I do, what type should it be? none? Or maybe another one? This is the trickiest part, I think
  • In the database: do I just need to put the user_company field in the project-user-mm table? Or do I also need to put a companies field in the project table?

Sorry for the extensive post but I wanted to be as clear as possible in my explanation. I would appreciate a lot the help since I cannot find any similar examples online. Thank you in advance!

Source