I have two tables, AclGroups and AclPermissions, and I want to create a hasMany relationship between them, i.e AclGroups has many AclPermissions.
The condition to determine whether a group owns a given permission is done in a single bitwise check. This is what i'm trying to do:
SELECT
*
FROM
acl_groups
JOIN
acl_permissions ON acl_permissions.permission & acl_groups.permission != 0
In AclGroupsTable I have tried the following:
$this->hasMany('AclPermissions', [
'className' => 'AclPermissions',
'foreignKey' => 'permission',
'conditions' => [
'AclPermissions.permission & AclGroups.permission !=' => 0
]
]);
But that just gives me
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'aclgroups.permission' in 'where clause'
In my controller I do:
$this->AclGroups->find('all')->contain(['AclPermissions']);
I suppose the real question is: Is there a way I can change the conditions of the ON clause in the query that fetches associated records
aclgroups != acl_groups, ie it's unclear whether the code you are showing here is what you are actually using, which is always problematic. That being said, please include the code that you use to build your query,hasManyassociations are retrieved in a separate query unless explicitly using joins. - ndmAclGroupsTable. The rest of the class is just baked. The only other line of code is a finder in my controller.$this->AclGroups->find('all')->contain(['AclPermissions']);and that's the full extent of it - Aidan Haddon-Wrightacl_groups(default CakePHP convention for a camel casedAclGroups) and the error message that usesaclgroups(no underscore), it wasn't clear whether you maybe were using joins (where your conditions would generally work) and just had a typo somewhere (could also be an additional problem). - ndm