⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Multiple Relationship Fields



OziBen
  • profile picture
  • Member

Posted 30 September 2012 - 19:55 PM

Hello,

I'm trying to use GroceryCRUD to allow me to manage a complex set of reporting permissions.

For simplicity I have:

a Users table:

User_id INT
username VARCHAR(45)

a Permission table:

Permission_id INT
Permission_Name VARCHAR(45)

and a User_has_Permission table

User_id INT
Permission_id INT
priority INT

GroceryCrud manages this perfectly with:

$crud->set_relation_n_n('Permissions','User_has_Permission','Permission','User_id','Permission_id','Permission_Name','priority');

(there are also Roles, and Roles_has_Permissions, along with Users_has_Roles tables, but they all follow the same principal).

However, I need to introduce a "scope" parameter within a permission, so a user can be constrained to a Reporting Scope (the separate Reporting function would check the scope and act accordingly), and I was trying to do it as an additional column on the Relation Table e.g:

User: User_ID = 1, username = 'john'
Permission: Permission_ID = 1, Permission_Name = Run_Office_Report
User_has_Permission: User_id = 1, Permission_id = 1, Scope = array('London', 'New York');

However, I have tried to find a way I can manage this data neatly in GC, but cannot.

I really don't want to have to add the column in the Permission Table, as it could mean thousands of additional rows, and that would make adding the permission to users or roles messy.

Anyone any thoughts?

Thanks,

Ben.

j-gun
  • profile picture
  • Member

Posted 01 October 2012 - 06:13 AM

@oziben

I suggest you to use the set_model from grocery crud like these:
 $crud = new grocery_CRUD();
$crud->set_model('custom_mode');


and override the [u][b]get_list[/b][/u] grocery crud model function inside your custom model.