We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

User and Group model as handler

Hi,

I need to have a ticket handler field under my ticket model. Hanlder can be a user or a team. How I can configure it. I have separate tables for users and teams.

It's possible, but I think more complicated than necessary to have a single field that can point to one of multiple tables. You won't be able to use the automatic relationships if you do.

Maybe have 3 fields? 1 field records the type of handler, 1 field has a value if the handler is a user (ie, the username) and 1 field has a value if the handler is a team (ie: team name/id).

Your model can then have 1 relationship between the model and user tables, and 1 relationship between the model and team table. Which one you access depends on the value of the field that records the type of handler.

To make your life a little easier, you could write custom getHandler() and setHandler() methods that encapsulate the necessary logic.