Hello there,
I've been testing and using GroceryCrud for a month now. It works well, i'm still discovering stuff.
I'm stuck with some relationships. See my database structure :
[attachment=682:dbstructure.png]
I have a controller that displays "articles" for a given "numero". That works well.
I set a relation on fk_redacteur with the "member" table, and then i can get users' names.
What i want to do is : set a relation on the "member" table, so i can get users' names, but when i edit my "article" and choose my user related to it, i want that user to belong to a specific group (example : group identifiant : 3). Then when I edit my article, i get to choose only a user that belongs to group 3 and not every user in the member table. Do you see what I mean ?
Well, then, my controller :
function articles($id) { echo "Affichage des articles"; $this->grocery_crud->set_theme('datatables'); $this->grocery_crud->set_table('magp3_article'); $this->grocery_crud->display_as('fk_numero','Numero'); $this->grocery_crud->display_as('fk_page','Page'); $this->grocery_crud->display_as('fk_redacteur','Rédacteur'); $this->grocery_crud->unset_read(); //relation a mettre pour le add article $this->grocery_crud->set_relation('fk_page', 'magp3_page', 'MagP3 n°{fk_numero} - {description}', array('fk_numero' => $id)); $this->grocery_crud->set_primary_key('id_redacteur','magp3_groupe_redacteur'); $this->grocery_crud->set_relation('fk_redacteur','phpboost_member','login'); // relation A $this->grocery_crud->set_relation('fk_redacteur','magp3_groupe_redacteur','{id_redacteur}',array('id_groupe' => 3)); // relation B //Ce where sert pour filtrer la liste $this->grocery_crud->where('fk_numero',$id); //validation $this->grocery_crud->required_fields('description', 'fk_page'); //affichage $output = $this->grocery_crud->render(); $this->_example_output($output); }
Seen the code ? So :
- when I set "relation A" only, I get only the user name, and i have to choose between all users in the member table
- when I set "relation B" only, I get only the user ID, but I have to choose between users of the group 3
I'm trying to find a way to combine the two relations, but how ? That's not a n to n relation (in my opinion, which you can discuss), and when I set both relations, only the last survives.
I've been searching the web for a couple of weeks now, whitout any success.
Do you have any idea ? I'm trying to use GroceryCrud the cleanest way possible. Do I have to use callbacks ? Is there a simple way to do this ?
Thanks for your help ;)