Last active
December 15, 2015 23:08
-
-
Save cameroncf/5337589 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In Permission.cfc: | |
property name="groups" fieldtype="many-to-many" cfc="Group" | |
type="array" singularname="Group" | |
fkcolumn="user_permission_id" inversejoincolumn="user_group_id" | |
linktable="user_permission_link" inverse="true"; | |
public void function addGroup(required Group group) { | |
arguments.group.addPermission(this); | |
} | |
public void function removeGroup(required Group group) { | |
arguments.group.removePermission(this); | |
} | |
In Group.cfc: | |
property name="permissions" fieldtype="many-to-many" cfc="Permission" | |
type="array" singularname="Permission" | |
fkcolumn="user_group_id" inversejoincolumn="user_permission_id" | |
linktable="user_permission_link" orderby="sort"; | |
public void function addPermission(required Permission permission) { | |
if (not hasPermission(arguments.permission)) { | |
// set this side | |
arrayAppend(variables.permissions,arguments.permission); | |
// set the other side | |
arrayAppend(arguments.permission.getGroups(),this); | |
} | |
} | |
public void function removePermission(required Permission permission) { | |
if (hasPermission(arguments.permission)) { | |
// set this side | |
var index = arrayFind(variables.permissions,arguments.permission); | |
if (index gt 0) { | |
arrayDeleteAt(variables.permissions,index); | |
} | |
// set the other side | |
index = arrayFind(arguments.permission.getGroups(),this); | |
if (index gt 0) { | |
arrayDeleteAt(arguments.permission.getGroups(),index); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment