In an app I'm working on now, I get a Group's permissions (for access
to a Section) like this:
/* fetch the permissions for this group
*/
$perms = $this->Acl->Aco->find(
'all',
array(
'fields' => array('Aco.foreign_key'),
'conditions' => array(
'Aco.model' => 'Section',
'Aco.id = Permission.aco_id'
),
'recursive' => -1,
'joins' => array(
array(
'table' => 'aros',
'alias' => 'Aro',
'type' => 'INNER',
'conditions'=> array(
'Aro.model' => 'Group',
"Aro.foreign_key = ${group_id}"
)
),
array(
'table' => 'aros_acos',
'alias' => 'Permission',
'type' => 'INNER',
'conditions'=> array(
'Permission.aro_id = Aro.id',
'Permission._read >= 0'
)
)
)
)
);
Group model:
public $actsAs = array (
'Acl' => 'requester',
'Tree' => array(
'parent' => 'parent_id',
'left' => 'lft',
'right' => 'rght'
)
);
Section model:
public $actsAs = array(
'Tree' => array(
'parent' => 'parent_id',
'left' => 'lft',
'right' => 'rght'
),
'Sluggable' => array(
'translation' => 'utf-8',
'separator' => '_',
'label' => array('name'),
'length' => 128,
'overwrite' => true
),
'Acl' => 'controlled'
);
There are no other models (eg. AclAro) required.
On Tue, Jul 14, 2009 at 2:39 AM, womble<[email protected]> wrote:
>
> I'm getting an annoying error: Unknown column 'xxxxxx' in 'where
> clause'
>
> The error is correct based on the SQL that cake is generating. But I
> don't think cake should be generating the SQL it is.
>
> When accessed via the AclAro model (below) it produces the desired
> results - I get data from either the Group or User Model based on the
> text content of AclAro.model - the SQL generated contains a seperate
> LEFT JOIN for each condition.
>
> class AclAro extends AppModel {
> var $name ='AclAro';
> var $useTable = 'aros';
> var $actsAs = array('Tree');
>
> var $belongsTo = array(
> 'Group' => array(
> 'className' => 'Group',
> 'foreignKey' => 'foreign_key',
> 'conditions' => array('AclAro.model' =>
> 'Group'),
> 'dependent' => false
> ),
> 'User' => array(
> 'className' => 'Acl.AclUser',
> 'foreignKey' => 'foreign_key',
> 'conditions' => array('AclAro.model' =>
> 'User'),
> 'dependent' => false
> )
> );
>
> }
>
>
> However, I want to retrieve the User/Group data from another model
> Permission that is associated with AclAro (below). When I try to get
> the desired data using 'recursive' => 2 it produces the error. Cake
> reworks the SQL, and attempts to make 1 SQL query for each each Group/
> User and tries to apply the condition set in AclAro to the Group/User
> table (the condition is a field in AclAro so doesn't exist in the
> Group/User table hence the error when the SQL is run) i.e. it ignores
> the AclAro condition on AclAro and tries to apply it to the wrong
> table (by attempting to make 1 SQL query for each group/user the LEFT
> JOIN's are removed).
>
> class Permission extends AppModel {
> var $useTable = 'aros_acos';
>
> public $belongsTo = array(
> 'AclAro' => array(
> 'className' => 'AclAro',
> 'foreignKey' => 'aro_id',
> ),
> );
> }
>
>
> In my method in the Permissions controller I'm using:
>
> $params = array('conditions' => array('aco_id' => 103),
> 'recursive'
> => 2); // hardcoded the 103 for testing
> $permissions = $this->AclPermission->find('all',$params);
>
>
>
> Now I'm not sure if I'm doing something wrong or if its cake just
> stuffing something up. But I know I'm not getting the result I want.
>
> Please help....................
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---