⚠ 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

where in relation 1 to n or n_n



carlinchisart
  • profile picture
  • Member

Posted 03 March 2012 - 15:58 PM

Hi all,

I have one question, I search in the forum but i don't find any topic about this.

My question is:

In a relation 1 to N i have to get only some data of the table, no all data of table, so in my table i have one field to know what type of data is, so in grocery i use a callback_add_field function to create a select manually, and work ok, but i see in the forum the where function in a creation of the relation, so i try to use.

 $crud->set_relation('id_parametro','parametros', 'nombre_parametro')->where('tipo_parametro', 'modalidad asesoria');




the table that i use to create the select is


CREATE TABLE IF NOT EXISTS `parametros` (
`id_parametros` int(10) unsigned NOT NULL AUTO_INCREMENT,
`tipo_parametro` varchar(255) DEFAULT NULL,
`nombre_parametro` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id_parametros`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=67 ;
--
-- Dumping data for table `parametros`
--
INSERT INTO `parametros` (`id_parametros`, `tipo_parametro`, `nombre_parametro`) VALUES
(1, 'modalidad asesoria', 'Chat programado'),
(2, 'modalidad asesoria', 'Chat específico para el tema consultado'),
(3, 'modalidad asesoria', 'Skipe o por programa de conferencia'),
(4, 'modalidad asesoria', 'Telefónicamente'),
(5, 'modalidad asesoria', 'Por correo electrónico'),
(6, 'modalidad asesoria', 'Presencialmente'),
(7, 'modalidad seguimiento', 'Por Formato'),
(8, 'modalidad seguimiento', 'Presencial'),
(9, 'modalidad seguimiento', 'Telefónico'),
(10, 'modalidad seguimiento', 'Vía correo electrónico'),
(11, 'modalidad seguimiento', 'Skipe o programa de conferencia virtual'),
(12, 'modalidad seguimiento', 'Otro medio'), .....................


so the field tipo_parametro is the valua that i use to creade a select, i can use the where of grocery for search the data and i don't have to use the callback_add_field function?


thanks,
and more more thanks for this framewok.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 03 March 2012 - 16:40 PM

Hello @carlinchisart and welcome to the forum

I think you don't search very good at the forum (just kidding it was difficult even for me to remember where I answered this question )

http://www.grocerycr...indpost__p__470

If you cannot wait for the new release, you can always download the last version from trunk ( If you don't know how just read http://www.grocerycr...p__448#entry448 )

carlinchisart
  • profile picture
  • Member

Posted 03 March 2012 - 16:52 PM

HI @web-johnny,

firts more, more thanks for your work!!!!

so if this topic can i do in the next version, i download from trunk, i do this and i coment about.

sorry for my English i speak spanish

carlinchisart
  • profile picture
  • Member

Posted 03 March 2012 - 17:34 PM

hi @web-johnny

i download from trunk, and i doed this in my relation


$crud->set_relation('id_parametro','parametros', 'nombre_parametro',array('tipo_parametro' =>'modalidad asesoria'));


so this solution work perfect!!!!!

but i have problem, in a callback_escape_insert function in my proyect i use this function, but when change the grocery crud the render no work, my page is white, if i comment this line
$crud->callback_escape_insert(array($this,'registroUsuario')); 
the render work ok and i see all ok.

so the other problem is when i try to upload file, i edit de grocery config to add zip an rar file type, but when i try to upload a file y see this

'An error has occurred on uploading.' this message is with all file type, txt, ppt, doc, zip, rar

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 03 March 2012 - 18:16 PM

all the callback_escape_something are renamed to callback_something. So for example the callback_escape_insert is renamed to callback_insert . Just a find and replace of all the "callaback_escape" to "callback" will fix the problem ;)

As for the second problem with the upload it's really strange. Are you sure that you have change the correct config? The config is the :


$config['grocery_crud_file_upload_allow_file_types']


and NOT the


$config['grocery_crud_image_upload_allow_file_types'] = 'gif|jpeg|jpg|png';


So in your case will be:


$config['grocery_crud_file_upload_allow_file_types'] = 'zip|rar|gif|jpeg|jpg|png|tiff|doc|docx|txt|odt|xls|xlsx|pdf|ppt|pptx|pps|ppsx|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2';


Can you just copy-paste your grocery_crud.php config file to the forum? Just to check if everything is well inserted.

carlinchisart
  • profile picture
  • Member

Posted 04 March 2012 - 15:29 PM

hi @web-johnny

the function callback work ok, tanks for your help,

and this is the config file


<?php
//For view all the languages go to the folder assets/grocery_crud/languages/
$config['grocery_crud_default_language'] = 'spanish';

// There are only three choices: "uk-date" (dd/mm/yyyy), "us-date" (mm/dd/yyyy) or "sql-date" (yyyy-mm-dd)
$config['grocery_crud_date_format'] = 'sql-date';

//If the set_relation data is bigger than the specified number then call all the data with ajax every time the user types a letter.
$config['grocery_crud_set_relation_max_data_without_ajax'] = 150;

$config['grocery_crud_image_upload_allow_file_types'] = 'gif|jpeg|jpg|png';
$config['grocery_crud_image_upload_max_file_size'] = '10MB'; //ex. '10MB' (Mega Bytes), '1067KB' (Kilo Bytes), '5000B' (Bytes)
$config['grocery_crud_image_upload_default_dir'] = 'assets/uploads/images';
$config['grocery_crud_image_upload_default_url'] = 'assets/uploads/images';
$config['grocery_crud_image_upload_max_width'] = 1024; //pixels
$config['grocery_crud_image_upload_max_height'] = 768; //pixels
$config['grocery_crud_image_upload_thumb_width'] = 100; //pixels
$config['grocery_crud_image_upload_thumb_height'] = 75; //pixels
$config['grocery_crud_image_upload_create_thumbnail'] = true;

$config['grocery_crud_file_upload_allow_file_types'] = 'zip|tar|gif|jpeg|jpg|png|tiff|doc|docx|txt|odt|xls|xlsx|pdf|ppt|pptx|pps|ppsx|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2';
$config['grocery_crud_file_upload_max_file_size'] = '20MB'; //ex. '10MB' (Mega Bytes), '1067KB' (Kilo Bytes), '5000B' (Bytes)
$config['grocery_crud_file_upload_default_path_folder'] = 'assets/uploads/files';
$config['grocery_crud_file_upload_default_url'] = 'assets/uploads/files';


but the problem is with all files are generate a error, images doc, ppt, and others.

other question, sometime the website grocerycrud.com is offline, this is normal? what I mean is that if you know that this happens, i don't want to insult.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 16:19 PM

Did you copy all the files? When you are updating grocery CRUD you have to copy all the files and folders and not only the library. Make sure that you have copied all the files and folders and you will not have any problem for sure.

As for the hosting, it really SUCKS :angry: . I have a new hosting plan because the bandwidth now it's much more than before ( this is a good thing :) ).

But I send them EVERY SINGLE day email to fix this website issues and I am really peesed off of them and I will probably change the hosting . It is just too boring to change hosting and it is only 1 month that I am with them.

I don't want to tell the name for now, but when I change the hosting I will have a whole topic for them , just to everybody knows why to NOT have hosting with them.

Sorry for the offline site , I really do my best every time to fix it.

carlinchisart
  • profile picture
  • Member

Posted 04 March 2012 - 16:46 PM

don't worry! your work is gread!!! so I think my problem is i copy all files and the javascript folder in the new version is diferent the files (order the files) so i delete all folder assets and copy the new folder.


but the problem remains the same, (i take a printScreen but i don't fine how i cand attach to topic :( )

so in the image i see the file try to upload but generate an error mesage, so i check the permissions of the upload folder and i change the permissions to 777 and the file upload!!!!!!!!!!! i doed some test so i see the file with special character is not allowed to upload.

carlinchisart
  • profile picture
  • Member

Posted 04 March 2012 - 17:06 PM

so i have other question, or other problem, in a n_n relation i have this

 $crud->set_relation_n_n('Temas de interes INCI y TIC', 'institucion_entereses_incitic', 'entereses_incitic', 'codigo_tic', 'id_parametro', 'nombre_parametro','priority');


and this are my tables in the db


CREATE TABLE IF NOT EXISTS `entereses_incitic` (
`id_parametro` int(11) NOT NULL AUTO_INCREMENT,
`tipo_interes` varchar(20) COLLATE utf8_spanish_ci NOT NULL,
`nombre_parametro` varchar(100) COLLATE utf8_spanish_ci NOT NULL,
PRIMARY KEY (`id_parametro`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci AUTO_INCREMENT=15 ;

CREATE TABLE IF NOT EXISTS `institucion` (
`codigo_tic` varchar(20) NOT NULL,
`id_municipio` int(10) unsigned NOT NULL,
`nom_institucion` varchar(200) NOT NULL,
`direccion_insititucion` varchar(500) NOT NULL,
`telefono_institucion` varchar(20) NOT NULL,
`fax_institucion` varchar(20) DEFAULT NULL,
`email_institucion` varchar(500) NOT NULL,
`id_parametro_tipo_entidad` int(10) unsigned DEFAULT NULL,
`id_parametro_ambito` int(10) unsigned DEFAULT NULL,
`id_parametro_clase_entidad` int(10) unsigned DEFAULT NULL,
`nombre_contacto` varchar(100) NOT NULL,
`email_contacto` varchar(100) NOT NULL,
`cargo_contacto` varchar(45) NOT NULL,
`telefono_contacto` varchar(20) NOT NULL,
`celular_contacto` varchar(20) DEFAULT NULL,
`sitio_web` varchar(45) DEFAULT NULL,
`id_parametro_sector` varchar(45) NOT NULL,
`nombre_rector` varchar(45) NOT NULL,
`nombre_responsable_tecnologia` varchar(45) DEFAULT NULL,
`cargo_resp_tec` varchar(45) DEFAULT NULL,
`tiempo_resp_tec` varchar(45) DEFAULT NULL,
`celular_resp_tec` varchar(45) DEFAULT NULL,
`correo_resp_tec` varchar(45) DEFAULT NULL,
`num_usuarios_ciegos` int(10) unsigned NOT NULL,
`num_usuarios_baja_vision` int(10) unsigned NOT NULL,
`atiende_pdv` tinyint(1) DEFAULT NULL,
`tecnologias_pdv` tinyint(1) DEFAULT NULL,
`id_usuario` int(10) unsigned NOT NULL,
PRIMARY KEY (`codigo_tic`),
KEY `INSTITUCION_FKIndex3` (`id_municipio`),
KEY `INSTITUCION_FKIndex7` (`id_usuario`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `institucion_entereses_incitic` (
`id_parametro` int(11) NOT NULL,
`codigo_tic` varchar(20) NOT NULL,
`priority` int(11) NOT NULL,
PRIMARY KEY (`id_parametro`,`codigo_tic`),
UNIQUE KEY `codigo_tic` (`codigo_tic`),
UNIQUE KEY `id_parametro` (`id_parametro`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


the render work ok, but the data no save in de table, in the same view i have other n_to_n relation and this relation work ok

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 17:33 PM

[quote name='carlinchisart' timestamp='1330879577' post='690']
don't worry! your work is gread!!! so I think my problem is i copy all files and the javascript folder in the new version is diferent the files (order the files) so i delete all folder assets and copy the new folder.


but the problem remains the same, (i take a printScreen but i don't fine how i cand attach to topic :( )

so in the image i see the file try to upload but generate an error mesage, so i check the permissions of the upload folder and i change the permissions to 777 and the file upload!!!!!!!!!!! i doed some test so i see the file with special character is not allowed to upload.
[/quote]

I checked it also with special characters . For example I have tested the file "test 45 @#$^789901!$)_=+&ελληνικά-greeklish.jpg" that also included greek letters not only special characters. But it is still uploading. It is weird. Please can you copy the message of you firebug ? For example: [attachment=56:2012-03-04_173206.png].

To attach an image you have to press the button below right (More Reply Options)

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 17:37 PM

[quote name='carlinchisart' timestamp='1330880786' post='691']
so i have other question, or other problem, in a n_n relation i have this

 $crud->set_relation_n_n('Temas de interes INCI y TIC', 'institucion_entereses_incitic', 'entereses_incitic', 'codigo_tic', 'id_parametro', 'nombre_parametro','priority');


and this are my tables in the db


CREATE TABLE IF NOT EXISTS `entereses_incitic` (
`id_parametro` int(11) NOT NULL AUTO_INCREMENT,
`tipo_interes` varchar(20) COLLATE utf8_spanish_ci NOT NULL,
`nombre_parametro` varchar(100) COLLATE utf8_spanish_ci NOT NULL,
PRIMARY KEY (`id_parametro`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci AUTO_INCREMENT=15 ;

CREATE TABLE IF NOT EXISTS `institucion` (
`codigo_tic` varchar(20) NOT NULL,
`id_municipio` int(10) unsigned NOT NULL,
`nom_institucion` varchar(200) NOT NULL,
`direccion_insititucion` varchar(500) NOT NULL,
`telefono_institucion` varchar(20) NOT NULL,
`fax_institucion` varchar(20) DEFAULT NULL,
`email_institucion` varchar(500) NOT NULL,
`id_parametro_tipo_entidad` int(10) unsigned DEFAULT NULL,
`id_parametro_ambito` int(10) unsigned DEFAULT NULL,
`id_parametro_clase_entidad` int(10) unsigned DEFAULT NULL,
`nombre_contacto` varchar(100) NOT NULL,
`email_contacto` varchar(100) NOT NULL,
`cargo_contacto` varchar(45) NOT NULL,
`telefono_contacto` varchar(20) NOT NULL,
`celular_contacto` varchar(20) DEFAULT NULL,
`sitio_web` varchar(45) DEFAULT NULL,
`id_parametro_sector` varchar(45) NOT NULL,
`nombre_rector` varchar(45) NOT NULL,
`nombre_responsable_tecnologia` varchar(45) DEFAULT NULL,
`cargo_resp_tec` varchar(45) DEFAULT NULL,
`tiempo_resp_tec` varchar(45) DEFAULT NULL,
`celular_resp_tec` varchar(45) DEFAULT NULL,
`correo_resp_tec` varchar(45) DEFAULT NULL,
`num_usuarios_ciegos` int(10) unsigned NOT NULL,
`num_usuarios_baja_vision` int(10) unsigned NOT NULL,
`atiende_pdv` tinyint(1) DEFAULT NULL,
`tecnologias_pdv` tinyint(1) DEFAULT NULL,
`id_usuario` int(10) unsigned NOT NULL,
PRIMARY KEY (`codigo_tic`),
KEY `INSTITUCION_FKIndex3` (`id_municipio`),
KEY `INSTITUCION_FKIndex7` (`id_usuario`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `institucion_entereses_incitic` (
`id_parametro` int(11) NOT NULL,
`codigo_tic` varchar(20) NOT NULL,
`priority` int(11) NOT NULL,
PRIMARY KEY (`id_parametro`,`codigo_tic`),
UNIQUE KEY `codigo_tic` (`codigo_tic`),
UNIQUE KEY `id_parametro` (`id_parametro`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


the render work ok, but the data no save in de table, in the same view i have other n_to_n relation and this relation work ok
[/quote]

This is because you have to rename your first string to : temas_de_interes (it has to have underscores, it is like a database field) and just have a display as for this, for example:


$crud->set_relation_n_n('temas_de_interes', 'institucion_entereses_incitic', 'entereses_incitic', 'codigo_tic', 'id_parametro', 'nombre_parametro','priority');
$crud->display_as('temas_de_interes','Temas de interes INCI y TIC');


This will make it work fine.

carlinchisart
  • profile picture
  • Member

Posted 04 March 2012 - 18:08 PM

hi @web-johnny

thanks for your answers!!!

so i follow your instrucction and attach the image

[attachment=58:errorLoadFile2.jpeg]

[attachment=59:errorLoadFile3.jpeg]

the name of file is Exposición_BaseDatosDistribuidas.rar

with the other question in n_to_n relation i doed the change and the solution work perfect!!!!!!!!!!!!!!! more, more thanks you!!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 18:29 PM

As I see at your previous post you have:


$config['grocery_crud_file_upload_allow_file_types'] = 'zip|tar|gif...


zip and tar and NOT rar so change it to:


$config['grocery_crud_file_upload_allow_file_types'] = 'zip|rar|gif|jpeg|jpg|png|tiff|doc|docx|txt|odt|xls|xlsx|pdf|ppt|pptx|pps|ppsx|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2';


BUT still what this the 1 thing!!! I don't understand! Why 1? I also uploaded the same file name as yours and it is still working fine.

So if you don't have special_chars in your file everything works fine? I just want to understand what is happening. For example if you rename the file to test.rar it will work?

It is a very weird message..!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 18:32 PM

Did you use any callback_upload or callback_before_upload or callback_after_upload?

carlinchisart
  • profile picture
  • Member

Posted 04 March 2012 - 18:53 PM

in this item i don't use any callback function.

and i change the configo for rar file type i see the same error.

so i change the name of .rar file but the error is the same, so i probe with other file that have a ñ character and the error is the same

[attachment=60:errorLoadFile6.png]

so i think the problem is my pc my Linux SO, in other occasions i have this problem and i can't open the file becouse remplace the character for other simbols.

so you don't worry for this.

I have other question, but i think in open other topic.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 04 March 2012 - 21:10 PM

Just changed hosting.

Don't EVER THINK to have hosting at thrustvps . It really sucks! After so many messages the server is still down and I track my server and it was uptime like 95% (this means 2h per day my website was DOWN!!)

Thanks god the new hosting has great support and I changed hosting plan in just 1 hour. By the way my new hosting is webhostingbuzz and it looks great :D

carlinchisart
  • profile picture
  • Member

Posted 06 March 2012 - 03:04 AM

great!!!! becouse when i working read the forum, the site was down and i can't read, so good luck!!!!!!!!!!!!!!!! and more more thanks for your work

carlinchisart
  • profile picture
  • Member

Posted 24 March 2012 - 20:08 PM

hi web-jonny, i have one question whit the n-n relation, mi problem i thinks is becouse my primary key is created by one function that i call whit this

$crud->callback_before_insert(array($this,'determinarCodigoTic'));

the function work ok, becouse my table institucion create the register ok, and the primary key, but the problem is the relation n-n no register, if i edit the register and add the n-n elements this register ok, but when i add new data the register n-n no work, i think the problem is the callback_before_insert. this is my function, but i don't know the problem


function determinarCodigoTic($valor){
$query = $this->db->get('municipio');

foreach ($query->result() as $row){
if($row->id_municipio==$valor['id_municipio']){
$departamentoId=$row->id_departamento;
}
}
$query= $this->db->get('departamento');
foreach ($query->result() as $row){
if($row->id_departamento==$departamentoId){
$departamento=$row->nom_departamento;
}
}
$query= $this->db->get('parametros');
foreach ($query->result() as $row){
if($row->id_parametros==$valor['id_parametro_clase_entidad']){
$claseEntidad=$row->nombre_parametro;
}
else if($row->id_parametros==$valor['id_parametro_sector']){
$sector=$row->nombre_parametro;
}
else if($row->id_parametros==$valor['id_parametro_ambito']){
$ambito=$row->nombre_parametro;
}
}

$query= $this->db->query("SELECT * FROM institucion");
$consecutivo=$query->num_rows()+1;
$reducido=substr($claseEntidad,0,2).substr($departamento,0,3).substr($sector,0, 2).substr($ambito,0,2);
$valor['codigo_tic']= substr($claseEntidad,0,2).substr($departamento,0,3).substr($sector,0, 2).substr($ambito,0,2).$consecutivo;
return $valor;
}


the database estructure is the same that the my coment Posted 04 March 2012 - 12:06 PM

diego
  • profile picture
  • Member

Posted 23 January 2013 - 17:51 PM

[quote name='web-johnny' timestamp='1330882679' post='693']
This is because you have to rename your first string to : temas_de_interes (it has to have underscores, it is like a database field) and just have a display as for this, for example:


$crud->set_relation_n_n('temas_de_interes', 'institucion_entereses_incitic', 'entereses_incitic', 'codigo_tic', 'id_parametro', 'nombre_parametro','priority');
$crud->display_as('temas_de_interes','Temas de interes INCI y TIC');


This will make it work fine.
[/quote]

Great answer Jonny! I replaced my first string "Directores Peliculas" by "Directores_Peliculas" and then it worked very well. Before, the render was ok but not saving.

Congratulations for GroseryCrud. You save a lot of time to us (the programmers) :)