⚠ 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

Additional Information in n2n



Ben85
  • profile picture
  • Member

Posted 04 August 2018 - 22:26 PM

Hi All,

 

I just started using Grocery CRUD Enterprise with CodeIgnitor and I love it. First of all thanks for creating this awesome lib.

 

I successfully created a n2n relationship which is working great. But I would need to add some more information to the junctionTable. Its a connection between a user and a crew table where a crew can has multiple user or a user can has multiple crews. What I need to add is a timeframe from when to when the user will be on this crew, I already created two field "userincrew_from" and "userincrew_to".

 

Is there any way to let the user fill in those two information while editing the db entry?

$crud = $this->_getGroceryCrudEnterprise();
$crud->setSkin('bootstrap-v4');
$crud->setTable('Crew');
$crud->setSubject('Crew', 'Crews');
$crud->columns(['crew_name', 'company_id', 'user_id_crewboss', 'user_id_cook', 'user_id_geo', 'crewmember']);
$crud->displayAs('crew_name', 'Crewname');
$crud->displayAs('company_id', 'Company');
$crud->displayAs('user_id_crewboss', 'Crewboss');
$crud->displayAs('user_id_cook', 'Cook');
$crud->displayAs('user_id_geo', 'Geologist');
$crud->setRelation('company_id', 'Company', 'company_shortcut');
$crud->setRelation('user_id_crewboss', 'Users', '{user_firstname} {user_lastname}');
$crud->setRelation('user_id_cook', 'Users', '{user_firstname} {user_lastname}');
$crud->setRelation('user_id_geo', 'Users', '{user_firstname} {user_lastname}');
$crud->setRelationNtoN('crewmember', 'User_to_Crew', 'Users', 'crew_id', 'user_id', '{user_firstname} {user_lastname}');
$output = $crud->render();
$page = $page."/crews";
$this->view_output($data,$page,$output);

Thanks so much for you help,

Ben


larasmith
  • profile picture
  • Member

Posted 06 August 2018 - 00:04 AM

Hello!

 

Perhaps this could help: https://www.grocerycrud.com/enterprise/api-and-function-list/callbackBeforeInsert


Ben85
  • profile picture
  • Member

Posted 06 August 2018 - 23:16 PM

Hi Lara,

 

thanks for the link. After reading it I think that would work only to edit a field in the base table.

The field I want to edit is in the junction table. Since the keys are written there via GroceryCRUD I hope that it is possible to write even one more field into this table.

 

Thanks,

Ben


larasmith
  • profile picture
  • Member

Posted 07 August 2018 - 02:06 AM

Hi Ben!

 

Would it be a hassle if you create another GCRUD for the said values for user input?

Just a suggestion though.

 

:)


Ben85
  • profile picture
  • Member

Posted 15 August 2018 - 20:14 PM

Hi Lara,

 

sorry for the late answer.

To be honest it would be not optimal to have a second instance of GCRUD just for adding those two values. Especially since they are so connected to the crew table users would need to first create a crew and then add additional information in a second place.

 

Thanks for your help,

Ben