Forums

CC v5 list data and update 2 tables

jhaviro 31 Jul, 2015
Hello.

Here I come back with some questions. I tried to find some solution to this forum but I have not found the right answer.

I created a list CCV5 must read and update data in 2 tables.
Both tables have fields in common but are not related (they are MyISAM).
I tried creating two models, each with a table but only get extract, update and delete data from one of them. The other does nothing, me child even extracts data.

I want to display data from both tables to update the fields in common and delete records in both tables when needed.
I created a form CFv5 and works perfectly with a table but the second table does not update or visualize the data.

I just need a general and simple example of how CCv5 use with 2 tables edit and save the data. I am sure with a brief tutorial could fix it.

Many thanks in advance
GreyHead 01 Aug, 2015
Hi jhaviro,

I think that if you want to update or delete from two tables like this you will need to use Custom Code in your form. I'm not an expert in CC but I don't think that it can handle deletions or saves from two unrelated tables.

Bob
jhaviro 01 Aug, 2015
hello Bob

OK (I imagined it), but then I do not understand that it serves to create various models and each model to connect different tables. CCv5 not properly documented. I get not find any manual that explain the use of several models CCV5 ... In "theory" it seems to create the primary and foreign keys and relating them should work.
I've tried to change my InnoDB tables and create indexes and foreign key ... but does not work (at least automatically)
GreyHead 01 Aug, 2015
Hi Jhaviro,

You said that your tables were not related (apart from some common columns).

If you can define a relationship in MySQL terms then it may work, but as I say I am no expert in CC.

It might help to update ChronoForms to the latest 5.0.10 release as I noticed that there are some changes in the code that handles table relationships.

Bob
jhaviro 01 Aug, 2015
Indeed my tables are not related, but I also duplicated and a foreign key relationship and neither did. I'm sure I'm doing something wrong, so I wanted to ask a little tutorial on this section CCV5 not quite understand. Maybe there and I find I have not heard. A little help from the part of ccv5 use with various models and various tables.

If there is any part of this tutorial (CCv5 multi-table) can you send me the link?

Thank you very much for your time, help and advice!
jhaviro 02 Aug, 2015
Hello Bob.

I imagine it will be difficult for some kind of tutorial yourselves related CCv5 multitable and multi model, however, I would like to know your 100% super application. Certainly, all my difficulties have to do with my lack of knowledge in programming but I am very satisfied with the tool.
I'm actually creating an application that CF and CC could not have done.

I've come to a good solution including in the form of editing the following code that I share:


	$description = $form->data['orders']['description'];
	$created_by = $form->data['orders']['created_by'];
	$storage_path = $form->data["storage_path"];
	$unpublish_on = $form->data['orders']['unpublish_on'];
	$publish_on = $form->data['orders']['publish_on'];
	$slug = $form->data['orders']['slug'];
	$title = $form->data['orders']['title'];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Fields to update.
$fields = array(
		  $db->quoteName('description') . '='. $db->quote($description),
		  $db->quoteName('storage_path') . '='. $db->quote($storage_path),
		  $db->quoteName('unpublish_on') . '='. $db->quote($unpublish_on),
		  $db->quoteName('publish_on') . '='. $db->quote($publish_on),
		  $db->quoteName('title') . '='. $db->quote($title),
		  $db->quoteName('created_by') . '='. $db->quote($created_by),
		  $db->quoteName('slug') . '='. $db->quote($slug)
		);
 
$query->update($db->quoteName('#__docman_documents'))->set($fields);
$db->setQuery($query);


With this code I get update my table and the table of Docman (this is my goal). Attempt to create a united Docman application that allows me to keep track of orders related files.
In some cases, the fact of using CF or DC quite complicated custom code, but there are enough examples of syntax help (congratulations to your forum too)

I could not create the relationship between the tables because Docman stopped working properly.
Nor could I use cURL (first thought, best solution). I have come to make everything work but did not perform the form. No errors came to me, but not working.

For now, everything is working (although it takes me a long time, reading your forum and visits to many pages with assistance).
Now I shall include the code for the table that I created also update from docman.

I appreciate your time and I hope that when tengais some time hagais a small advanced tutoring CCv5 !! (If I have to pay if I pay a reasonable price)

Gracias!! Saludos!!
jhaviro 02 Aug, 2015
Hello again:
correct
Although the code is something simple, if wrong, can finally give some headache to someone. Copy and paste again.

 	$title = $form->data['orders']['title'];
	$description = $form->data['orders']['description'];
	$created_by = $form->data['orders']['created_by'];
	$unpublish_on = $form->data['orders']['unpublish_on'];
	$publish_on = $form->data['orders']['publish_on'];
	$slug = $form->data['orders']['slug'];
	$docman_document_id = $form-> data['orders']['docman_document_id'];
	
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Fields to update.
$fields = array(
		$db->quoteName('title') . '='. $db->quote($title),
		$db->quoteName('description') . '=' . $db->quote($description),
		$db->quoteName('storage_path') . '=' . $db->quote($storage_path),
		$db->quoteName('unpublish_on') . '=' . $db->quote($unpublish_on),
		$db->quoteName('publish_on') . '=' . $db->quote($publish_on),
		$db->quoteName('created_by') . '=' . $db->quote($created_by),
		$db->quoteName('slug') . '='. $db->quote($slug)
		);
$conditions = $db->quoteName('docman_document_id') . '=' . $db->quote($docman_document_id);

$query->update($db->quoteName('#__docman_documents'))->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->execute();


source of aid:
https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase

Thanks again
CIAO!
Erik66 01 Sep, 2015
Hello,

I also want to save data 2 to tables using CF. I found out this is perfectly possible with the built-in "DB Save" actions in the form's setup. If you simply drag and drop two DB Save actions into the setup, select different tables for each action, and then save the form, the form will not work correctly and you'll get a MySQL error message upon executing the form.

You actually need to change the "Model ID" of the second form. If you don't, the second DB Save action tries to store the same data into the table used in the first action again, creating the MySQL error (Duplicate Key Entry). When you change the Model ID of the second DB Save action (for instance to "Data2" instead of the default "Data") it actually works great. I bet you can extend this to storing data to even more tables, as long as you keep the Model ID unique for each DB Save action.

Best regards,

Erik
Erik66 02 Sep, 2015
Thank you Bob.

I have read that FAQ beforehand and met the requierments as well. I found that runing the form in an article using the plugin worked also for me, but I used the form in a module in this situation. Otherwise, saving to multiple databases works great as described above without any additional programming.

Best reagrds,

Erik
jhaviro 14 Oct, 2015
Hello, Erik66
What I tried to do to display and save data in related tables ... by LEFT JOIN or INNER JOIN.
This "in theory" also should be possible but the results were not correct. For reasons unknown to me, if I used -left or groups data INNER unable to eliminate the option to group ... Finally, the easiest option is to create a view within MySQL and make the consultation on the new table. The SQL code is much easier and avoid writing 100 lines of Ajax ... So, everything is automatic. (I have only tried to make SELECT queries, is not whether it will work UPDATE)

Indeed, to keep two tables need 2 models, one for each table.
for related tables, you need 2 models and foreing key ... then you should include the type of relationship and type of JOIN ... I've tried everything and the results are not correct ... default creates a query that lists the ID even put anything and groups the results even if you want to repeat data, will not let you.

I would like to leave a field next updates to make custom queries freely, that is, directly enter the SQL code to create the relationships without restrictions.

TYVM
javierp
This topic is locked and no more replies can be posted.