beforeAddRelatedRecord Delegate Class Method[Permalink]Return to Delegate class methods
SynopsisThe beforeAddRelatedRecord delegate class method can be implemented in any table's delegate class. It will be executed before any related record is added to that table's relationships. Since it will be fired for all relationships on the table, you will have to include logic to only execute if the relationship that you are targeting is being added to. Method Signature
Parameters
Returns
It is quite common to return a permission denied error from this method after doing some checks. e.g.
ExamplesExample 1: Permission Check
The above example requires a little bit of context to understand. This method is defined in the 'users' table. There is a relationship between the users table and the programs table called 'program_roles'. It keeps track of the roles that users have with respect to programs. There is a mirror relationshp in the programs table that goes to the users table, also named program_roles. Both the users table and the programs table contain rel_program_roles__roles() methods to define who can and cannot add to this relationship. However these don't discern on the content that is being added to the relationship, so it is still possible that an ineligible program could be added to the relationship via the users table (or vice versa). So, in the users table we defined the beforeAddRelatedRecord above which checks the permissions of the programs table to see if that particular program can be added to this relationship by this user. See Also
|