hİ Martin,
First so many thanks for your reply, But I can not fix my problem.
You are right I am trying to checking if the user has any of the
required permissions for a given request.
I write GroupPermission model to apply my query as cake-friendly
because I can not create Left Join operation on Group model.
I want to create these LEft Joins to make my operations easy
LEFT JOIN "groups" AS "Group" ON ("GroupPermission"."group_id" =
"Group"."id")
LEFT JOIN "permissions" AS "Permission" ON
("GroupPermission"."permission_id" ="Permission"."id")
LEFT JOIN "users" AS "User" ON ("User"."group_id" ="Group"."id")
I can not do these Left Joins without GroupPermission model.
if I use Group Model then the query will failed. Look at the codes
below and output
--------
if(($uid = (int)$this->Session->read('user')) > 0)
{
$conditions['User.id'] = $uid;
}
else
{
$conditions['GroupPermission.group_id'] = 0;
}
$conditions['Permission.name'] = $perm;
if($this->Group->findCount($conditions) == 0)
{
$this->flash("You are not allowed to enter this page!", "/");
exit();
}
Output is:
---------
Query: SELECT COUNT(*) AS "count"
FROM "groups" AS "Group"
WHERE "User"."id" = '1'
AND "Permission"."name" IN ('pages', 'pages/display', 'pages/display/
home')
Warning: SQL Error: ERROR: missing FROM-clause entry for table "User"
LINE 1: ...NT(*) AS "count" FROM "groups" AS "Group" WHERE
"User"."id... ^ in /home/ch/lappstack-0.9-beta-1/apache2/htdocs/
authentication/cake/libs/model/datasources/dbo_source.php on line 440
----------
Also I add foreign keys to my models
--------------
class GroupPermission extends AppModel
{
var $name = 'GroupPermission';
var $useTable = 'groups_permissions';
var $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'group_id'
),
'Permission' => array(
'className' => 'Permission',
'foreignKey' => 'permission_id'
)
);
}
class Group extends AppModel
{
var $name = 'Group';
var $hasMany = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'group_id'
)
);
var $hasAndBelongsToMany = array(
'Permission' => array(
'className' => 'Permission',
'joinTable' => 'groups_permissions',
'foreignKey' => 'group_id',
'associationForeignKey' => 'permission_id')
);
}
class Permission extends AppModel
{
var $name = 'Permission';
var $hasAndBelongsToMany = array(
'Group' => array(
'className' => 'Group',
'joinTable' => 'groups_permissions',
'foreignKey' => 'permission_id',
'associationForeignKey' => 'group_id')
);
}
------------
if you know another way or something else please let me know. Thanks
again Martin.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---