Welcome Guest, Not a member yet? Register   Sign In
Problem with a n_n relation
#1

[eluser]Unknown[/eluser]
Hello all,

I'm facing a puzzling problem with a n_n relationship.
I have two tables in my DB which I'm connecting through a third one :

TABLE 1 : permissions
Code:
id_perm (bigint, ai, pk) | label (varchar)

TABLE 2 : roles
Code:
id_role (int, ai, pk) | label (varchar)

TABLE 3 : permissions_roles
Code:
id (bigint) | id_perm (bigint) | id_role (int)
(note that this 'id' field is neither a key nor a unique field, it is only used for ordering purposes)

I have two controllers which use this relation: one with a CRUD on roles, and the other one with a CRUD on permissions. Here are the excerpts from both controllers.

roles.php:
Code:
$crud->set_relation_n_n($u->l('permissions'), 'permissions_roles', 'permissions', 'id_role', 'id_perm', 'label','id');

permissions.php:
Code:
$crud->set_relation_n_n($u->l('roles'), 'permissions_roles', 'roles', 'id_perm', 'id_role','label','id');
Strangely enough, the CRUD works perfectly fine on the roles.php page: I can add and edit roles, and define the attached permissions to these.
Whereas it does not work on the permissions.page: I can add or edit permissions ONLY if they have no roles attached.

Any idea why the relation is not working?

Kind regards




Theme © iAndrew 2016 - Forum software by © MyBB