⚠ 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

How to update a n n relation table



os123
  • profile picture
  • Member

Posted 15 July 2015 - 23:47 PM

Hi everybody
 
I'm new in grocerycrud, I have a  question. Is it possible to create a relation_n_n that contains data (date, for example) you must update.
 
For example:
 
I have 2 tables
Employe (id_employe, nom, prenom)
Action(id_action, type, libelle)
 
and the relation table
EmployeAction (id_employe, id_action, date)
 
I would like to update the  "EmployeAction" table from the "Employe" table.
Is this possible with set_relation_n_n () function? How?
 
Could you help me please

 


Paul Savostin
  • profile picture
  • Member

Posted 16 July 2015 - 00:00 AM

Hi! See docs on the grocery crud site and if after u will have a questions, write here :)


os123
  • profile picture
  • Member

Posted 16 July 2015 - 12:53 PM

Hi Paul, thank you for answer.
 
I saw the docs and like the example I am using this for the three tables 
 
 
$crud->set_relation_n_n('action', 'employeaction', 'action', 'id_employe', 'id_action', 'type', 'priority');
 
it works great, but my question is how can I enter information in the fields from the relation table in this case the date (or any other field)
 
what do you suggest? 

Paul Savostin
  • profile picture
  • Member

Posted 16 July 2015 - 17:08 PM

All u can do that only add values before in related table and than update in current. Dynamicly add values u cant. But I guess I saw here on the forum similar question... so let search


Raúl
  • profile picture
  • Member

Posted 18 July 2015 - 11:58 AM

Hi 

I am having a similar case and I agree with Paul: it seems there is no way to automatically update it. So, I am implementing both updates to "master" and "relation" table in the same callback. However, I am having problems to get selected items. For the "main" table, I am referring to $post_array['first_name']

 to get the entered value, but for the selected entries (as I may have several), I understand I should get an array with selected ones: could someone provide an example??

$this->grocery_crud->set_relation_n_n('assignedgroup','users_groups', 'groups', 'group_id', 'user_id', 'description');
    	  
$this->grocery_crud->display_as('username','Identificador');



....

$post_array['username']
foreach ($post_array['assignedgroup'] as $assigned)	  

Paul Savostin
  • profile picture
  • Member

Posted 18 July 2015 - 17:35 PM

I am not clearly understand your logic, can u explain more?