⚠ 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

Insertar en 3 tablas



beimar24

beimar24
  • profile picture
  • Member

Posted 22 April 2013 - 01:14 AM

Apreciados ingenieros  buen día

 

me gustaría saber como hacer para insertar en 3  tablas  

 

tb_personas    

campo  id_persona

campo  nombre_persona

 

 tb_empresas

campo id_empresa

campo razón_social

 

 

 

tb_personas_empresa

id_persona

id_empresa

estado

 

 

esto en php  lo haría con un sp o procedimiento almacenado 

pero utilizando grocery Crud 

no tengo idea como hacerlo 

 

alguien tiene  una idea de como llegar a hacerlo

 

de antemano quedo muy agradecido por su atención y colaboración

Cordialmente

Beimar trujillo 

 

 

 

 

 

 

 


davidoster

davidoster
  • profile picture
  • Member

Posted 22 April 2013 - 14:32 PM

http://www.systranet.com/translate/


beimar24

beimar24
  • profile picture
  • Member

Posted 22 April 2013 - 17:15 PM

Dear engineers good day


I would like to know how to to insert in 3 tables


tb_personas

id_persona field

PERSON_NAME field

 

  tb_empresas

id_empresa field

razón_social field

 

tb_personas_empresa

id_persona

id_empresa

state

 
this in php you would a stored procedure or sp

but using grocery Crud

I have no idea how to do it

 

someone has an idea of how to get to it

 

I am very grateful in advance for your attention and cooperation

cordially

Beimar trujillo


Zalo

Zalo
  • profile picture
  • Member

Posted 23 April 2013 - 05:23 AM

Te lo respondo en castellano y posteriormente lo copio abajo en ingles para el resto del mundo:

La manera de hacer lo que estas mencionando es con los callbacks de insert y update. Tenes 3 opciones:

1)Con callback_insert/update reemplazas la funcion de insert/update por defecto por una que definis vos... en esta simplemente haces los inserts que necesitas. (tenes la variable $post que te devuelve todos los campos del formulario).

 

2) Tambien podes dejar que una tabla la llene el GC con la funcion por defecto y llenar las otras dos con un callback_after_insert/update que corre despues del insert/update por defecto.

 

3) La tercer opcion es MUY parecida a la segunda, y es un callback_before_insert/update. Es basicamente lo mismo pero corre ANTES del insert/update (esto es util si la tabla que vas a dejar que se llene por defecto es la de union).

 

Ahora... esto es asumiendo que queres/necesitas insertar todos los datos dentro de un mismo formulario... si pudieras "dividirlos" lo mas practico seria que hagas un formulario para la empresa, uno para persona y en alguno de los 2 (o ambos) uses la funcion  set_relation_n_n que basicamente lo que hace es llenar la tercer tabla (aunque la utilidad de esto depende de que vaya dentro de state).

 

Documentacion (para las funciones q menciono): http://www.grocerycrud.com/documentation/options_functions

 

Now in English:

 

This is the same as before (or at least tries to be...) , but in English:

 

There are 3 ways of doing what you are asking:

 

 

1)You have the callback_insert/update functions that replace the default GC insert/update with a user defined one. In this new function you just create the inserts that you need for your tables. (You have a $post variable with all the fields from the form).

 

2) You may also let GC handle the insert/update of one table and use callback_after_insert/update to fill the other 2. This callback runs AFTER the default GC insert.

 

3) The other way is very similar to the second one and it uses callbac_before_insert/update. This callback is basically the same as the previous one but it runs BEFORE the default GC insert/update (this is useful if you want to let GC handle the joining table).

 

Now... this is assuming that you want/need to insert all the info in just one form... If you could split them the easiest way to go would be to have 1 form for the enterprise (empresa), one for the person (persona) and then use set_relation_n_n in one (or both) of them. This last function basically handles the join table (3rd one). (Keep in mind that this might or might not be a possible solution depending on the values of the state field).

 

Documentation: http://www.grocerycrud.com/documentation/options_functions

 

 

There... Spanish and English, everybody happy :D


jesus12345

jesus12345
  • profile picture
  • Member

Posted 29 September 2014 - 21:54 PM

hi, someone who can help me with this;

 

I need to add new fields at the form, I dont want replace fields from de data base, I want to add new fields at the form, but not in the database


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 30 September 2014 - 18:05 PM

Well u can set the same using $crud-> add_fields  - but make sure u unset them from the $_POST_ARRAY .. before returning it inside the callback_before_insert - else it will try to consider it as actual field and build a query around it which eventually will fail up...!!

 

Happy GCing :)


jesus12345

jesus12345
  • profile picture
  • Member

Posted 30 September 2014 - 21:31 PM

Well u can set the same using $crud-> add_fields  - but make sure u unset them from the $_POST_ARRAY .. before returning it inside the callback_before_insert - else it will try to consider it as actual field and build a query around it which eventually will fail up...!!

 

Happy GCing :)

 

Thanks friend!, that  was great. I Am learning to use GC. Again Thanks


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 01 October 2014 - 07:07 AM

learn it well ... it has many amazing usages :)

only way it helped me to great extent is when i started thinking out of the box.. for possibilities :)


jesus12345

jesus12345
  • profile picture
  • Member

Posted 01 October 2014 - 21:04 PM

learn it well ... it has many amazing usages :)

only way it helped me to great extent is when i started thinking out of the box.. for possibilities :)

 

Friend, how I can show the values from  $_POST_ARRAY, I'm  trying show it using the callback_before_insert, but I can´t


IDe

IDe
  • profile picture
  • Member

Posted 11 May 2015 - 19:39 PM

Te lo respondo en castellano y posteriormente lo copio abajo en ingles para el resto del mundo:

La manera de hacer lo que estas mencionando es con los callbacks de insert y update. Tenes 3 opciones:

1)Con callback_insert/update reemplazas la funcion de insert/update por defecto por una que definis vos... en esta simplemente haces los inserts que necesitas. (tenes la variable $post que te devuelve todos los campos del formulario).

 

2) Tambien podes dejar que una tabla la llene el GC con la funcion por defecto y llenar las otras dos con un callback_after_insert/update que corre despues del insert/update por defecto.

 

3) La tercer opcion es MUY parecida a la segunda, y es un callback_before_insert/update. Es basicamente lo mismo pero corre ANTES del insert/update (esto es util si la tabla que vas a dejar que se llene por defecto es la de union).

 

Ahora... esto es asumiendo que queres/necesitas insertar todos los datos dentro de un mismo formulario... si pudieras "dividirlos" lo mas practico seria que hagas un formulario para la empresa, uno para persona y en alguno de los 2 (o ambos) uses la funcion  set_relation_n_n que basicamente lo que hace es llenar la tercer tabla (aunque la utilidad de esto depende de que vaya dentro de state).

 

Documentacion (para las funciones q menciono): http://www.grocerycrud.com/documentation/options_functions

 

Now in English:

 

This is the same as before (or at least tries to be...) , but in English:

 

There are 3 ways of doing what you are asking:

 

 

1)You have the callback_insert/update functions that replace the default GC insert/update with a user defined one. In this new function you just create the inserts that you need for your tables. (You have a $post variable with all the fields from the form).

 

2) You may also let GC handle the insert/update of one table and use callback_after_insert/update to fill the other 2. This callback runs AFTER the default GC insert.

 

3) The other way is very similar to the second one and it uses callbac_before_insert/update. This callback is basically the same as the previous one but it runs BEFORE the default GC insert/update (this is useful if you want to let GC handle the joining table).

 

Now... this is assuming that you want/need to insert all the info in just one form... If you could split them the easiest way to go would be to have 1 form for the enterprise (empresa), one for the person (persona) and then use set_relation_n_n in one (or both) of them. This last function basically handles the join table (3rd one). (Keep in mind that this might or might not be a possible solution depending on the values of the state field).

 

Documentation: http://www.grocerycrud.com/documentation/options_functions

 

 

There... Spanish and English, everybody happy :D

Beso tu mano Zalo mi salvador !!! hace mucho estaba buscando solucion a esto ,,, gracias ,,, thanks !