Forums

Problem with model1 & model2 - help!

Stefani@ 16 Jun, 2014
First of all, congratulations for your work and support. I installed CC V5 in the sub folder of my website. My challenge is to create a table that references two as you can see here:
http://www.stefaniamoscato.it/scuolaweb/albo-pretorio
To Model1 (Article) no problem. But when I try to call up the table "nuvrj_attachments" with Model2 (Allegati), there is a mistake and I do not understand what it is.
Seeking a solution for almost a week, I read in the forums, but can not find an explanation. Can you tell me where am I wrong?
[attachment=0]Scuola Magenta - Amministrazione 2014-06-16 13-21-06.png[/attachment]
[attachment=1]Scuola Magenta - Amministrazione 2014-06-16 13-24-17.png[/attachment]
Stefani@ 20 Jun, 2014
252 views and no response? if I did not express well, I ask you to tell me and I will try to explain better (sorry but English is not my native language).
GreyHead 21 Jun, 2014
Hi Stefani@,

I'm afraid that you need Max for this. I haven't yet worked out how to join tables in CCV5 - particularly with
'HasMany' relationships.

I suggest that you use the Contact Us menu above to send him a message linking to this thread.

Bob
Stefani@ 22 Jun, 2014
Thank you for suggestion!
Max_admin 22 Jun, 2014
Hi,

Please clear the fields boxes in both models then enable the debug under the front or admin list, then copy and paste the debug info you get in the list page here or post a screenshot!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Stefani@ 23 Jun, 2014
Hello Max, here it is:
Array
(
[0] => SELECT `Extension`.`id` AS `Extension.id`, `Extension`.`name` AS `Extension.name` FROM `nuvrj_chronoengine_extensions` AS `Extension` WHERE `Extension`.`enabled` = '1' ORDER BY `Extension`.`ordering` ASC
[1] => SELECT `Connection`.`id` AS `Connection.id`, `Connection`.`title` AS `Connection.title`, `Connection`.`params` AS `Connection.params`, `Connection`.`extras` AS `Connection.extras`, `Connection`.`published` AS `Connection.published` FROM `nuvrj_chronoengine_connections` AS `Connection` WHERE `Connection`.`title` = 'Article' AND `Connection`.`published` = '1'
[2] => SELECT COUNT(*) AS `Article.count` FROM `nuvrj_content` AS `Article` WHERE `Article`.`state` = 1 AND `Article`.`catid` >= 23 AND `Article`.`catid` <= 27
[3] => SELECT `Article`.`id` AS `Article.id`, `Article`.`asset_id` AS `Article.asset_id`, `Article`.`title` AS `Article.title`, `Article`.`alias` AS `Article.alias`, `Article`.`title_alias` AS `Article.title_alias`, `Article`.`introtext` AS `Article.introtext`, `Article`.`fulltext` AS `Article.fulltext`, `Article`.`state` AS `Article.state`, `Article`.`sectionid` AS `Article.sectionid`, `Article`.`mask` AS `Article.mask`, `Article`.`catid` AS `Article.catid`, `Article`.`created` AS `Article.created`, `Article`.`created_by` AS `Article.created_by`, `Article`.`created_by_alias` AS `Article.created_by_alias`, `Article`.`modified` AS `Article.modified`, `Article`.`modified_by` AS `Article.modified_by`, `Article`.`checked_out` AS `Article.checked_out`, `Article`.`checked_out_time` AS `Article.checked_out_time`, `Article`.`publish_up` AS `Article.publish_up`, `Article`.`publish_down` AS `Article.publish_down`, `Article`.`images` AS `Article.images`, `Article`.`urls` AS `Article.urls`, `Article`.`attribs` AS `Article.attribs`, `Article`.`version` AS `Article.version`, `Article`.`parentid` AS `Article.parentid`, `Article`.`ordering` AS `Article.ordering`, `Article`.`metakey` AS `Article.metakey`, `Article`.`metadesc` AS `Article.metadesc`, `Article`.`access` AS `Article.access`, `Article`.`hits` AS `Article.hits`, `Article`.`metadata` AS `Article.metadata`, `Article`.`featured` AS `Article.featured`, `Article`.`language` AS `Article.language`, `Article`.`xreference` AS `Article.xreference` FROM `nuvrj_content` AS `Article` WHERE `Article`.`state` = 1 AND `Article`.`catid` >= 23 AND `Article`.`catid` <= 27 LIMIT 30
)
Stefani@ 23 Jun, 2014
[attachment=0]Albo pretorio on-line 2014-06-23 13-13-12.png[/attachment]
Max_admin 23 Jun, 2014
1 Likes
The associated model's data is not loaded, please clear the "foreign key" field and the primary key as well, let me know if the debug changes!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Stefani@ 23 Jun, 2014
Cleared...

Array
(
[0] => SELECT `Extension`.`id` AS `Extension.id`, `Extension`.`name` AS `Extension.name` FROM `nuvrj_chronoengine_extensions` AS `Extension` WHERE `Extension`.`enabled` = '1' ORDER BY `Extension`.`ordering` ASC
[1] => SELECT `Connection`.`id` AS `Connection.id`, `Connection`.`title` AS `Connection.title`, `Connection`.`params` AS `Connection.params`, `Connection`.`extras` AS `Connection.extras`, `Connection`.`published` AS `Connection.published` FROM `nuvrj_chronoengine_connections` AS `Connection` WHERE `Connection`.`title` = 'Article' AND `Connection`.`published` = '1'
[2] => DESCRIBE `nuvrj_content`
[3] => DESCRIBE `nuvrj_content`
[4] => SELECT COUNT(*) AS `Article.count` FROM `nuvrj_content` AS `Article` WHERE `Article`.`state` = 1 AND `Article`.`catid` >= 23 AND `Article`.`catid` <= 27
[5] => SELECT `Article`.`id` AS `Article.id`, `Article`.`asset_id` AS `Article.asset_id`, `Article`.`title` AS `Article.title`, `Article`.`alias` AS `Article.alias`, `Article`.`title_alias` AS `Article.title_alias`, `Article`.`introtext` AS `Article.introtext`, `Article`.`fulltext` AS `Article.fulltext`, `Article`.`state` AS `Article.state`, `Article`.`sectionid` AS `Article.sectionid`, `Article`.`mask` AS `Article.mask`, `Article`.`catid` AS `Article.catid`, `Article`.`created` AS `Article.created`, `Article`.`created_by` AS `Article.created_by`, `Article`.`created_by_alias` AS `Article.created_by_alias`, `Article`.`modified` AS `Article.modified`, `Article`.`modified_by` AS `Article.modified_by`, `Article`.`checked_out` AS `Article.checked_out`, `Article`.`checked_out_time` AS `Article.checked_out_time`, `Article`.`publish_up` AS `Article.publish_up`, `Article`.`publish_down` AS `Article.publish_down`, `Article`.`images` AS `Article.images`, `Article`.`urls` AS `Article.urls`, `Article`.`attribs` AS `Article.attribs`, `Article`.`version` AS `Article.version`, `Article`.`parentid` AS `Article.parentid`, `Article`.`ordering` AS `Article.ordering`, `Article`.`metakey` AS `Article.metakey`, `Article`.`metadesc` AS `Article.metadesc`, `Article`.`access` AS `Article.access`, `Article`.`hits` AS `Article.hits`, `Article`.`metadata` AS `Article.metadata`, `Article`.`featured` AS `Article.featured`, `Article`.`language` AS `Article.language`, `Article`.`xreference` AS `Article.xreference` FROM `nuvrj_content` AS `Article` WHERE `Article`.`state` = 1 AND `Article`.`catid` >= 23 AND `Article`.`catid` <= 27 LIMIT 30
)
Max_admin 23 Jun, 2014
1 Likes
its still not loaded for some reason, please try to change the relation type to "hasOne" ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Stefani@ 23 Jun, 2014
Array
(
[0] => SELECT `Extension`.`id` AS `Extension.id`, `Extension`.`name` AS `Extension.name` FROM `nuvrj_chronoengine_extensions` AS `Extension` WHERE `Extension`.`enabled` = '1' ORDER BY `Extension`.`ordering` ASC
[1] => SELECT `Connection`.`id` AS `Connection.id`, `Connection`.`title` AS `Connection.title`, `Connection`.`params` AS `Connection.params`, `Connection`.`extras` AS `Connection.extras`, `Connection`.`published` AS `Connection.published` FROM `nuvrj_chronoengine_connections` AS `Connection` WHERE `Connection`.`title` = 'Article' AND `Connection`.`published` = '1'
[2] => SELECT COUNT(*) AS `Article.count` FROM `nuvrj_content` AS `Article` LEFT JOIN `nuvrj_attachments` AS `Allegati` ON `Article`.`id` = `Allegati`.`parent_id` WHERE `Article`.`state` = 1 AND `Article`.`catid` >= 23 AND `Article`.`catid` <= 27 GROUP BY `Article`.`id`
[3] => SELECT `Article`.`id` AS `Article.id`, `Article`.`asset_id` AS `Article.asset_id`, `Article`.`title` AS `Article.title`, `Article`.`alias` AS `Article.alias`, `Article`.`title_alias` AS `Article.title_alias`, `Article`.`introtext` AS `Article.introtext`, `Article`.`fulltext` AS `Article.fulltext`, `Article`.`state` AS `Article.state`, `Article`.`sectionid` AS `Article.sectionid`, `Article`.`mask` AS `Article.mask`, `Article`.`catid` AS `Article.catid`, `Article`.`created` AS `Article.created`, `Article`.`created_by` AS `Article.created_by`, `Article`.`created_by_alias` AS `Article.created_by_alias`, `Article`.`modified` AS `Article.modified`, `Article`.`modified_by` AS `Article.modified_by`, `Article`.`checked_out` AS `Article.checked_out`, `Article`.`checked_out_time` AS `Article.checked_out_time`, `Article`.`publish_up` AS `Article.publish_up`, `Article`.`publish_down` AS `Article.publish_down`, `Article`.`images` AS `Article.images`, `Article`.`urls` AS `Article.urls`, `Article`.`attribs` AS `Article.attribs`, `Article`.`version` AS `Article.version`, `Article`.`parentid` AS `Article.parentid`, `Article`.`ordering` AS `Article.ordering`, `Article`.`metakey` AS `Article.metakey`, `Article`.`metadesc` AS `Article.metadesc`, `Article`.`access` AS `Article.access`, `Article`.`hits` AS `Article.hits`, `Article`.`metadata` AS `Article.metadata`, `Article`.`featured` AS `Article.featured`, `Article`.`language` AS `Article.language`, `Article`.`xreference` AS `Article.xreference`, `Allegati`.`id` AS `Allegati.id`, `Allegati`.`filename` AS `Allegati.filename`, `Allegati`.`filename_sys` AS `Allegati.filename_sys`, `Allegati`.`file_type` AS `Allegati.file_type`, `Allegati`.`file_size` AS `Allegati.file_size`, `Allegati`.`url` AS `Allegati.url`, `Allegati`.`uri_type` AS `Allegati.uri_type`, `Allegati`.`url_valid` AS `Allegati.url_valid`, `Allegati`.`url_relative` AS `Allegati.url_relative`, `Allegati`.`display_name` AS `Allegati.display_name`, `Allegati`.`description` AS `Allegati.description`, `Allegati`.`icon_filename` AS `Allegati.icon_filename`, `Allegati`.`access` AS `Allegati.access`, `Allegati`.`state` AS `Allegati.state`, `Allegati`.`user_field_1` AS `Allegati.user_field_1`, `Allegati`.`user_field_2` AS `Allegati.user_field_2`, `Allegati`.`user_field_3` AS `Allegati.user_field_3`, `Allegati`.`parent_type` AS `Allegati.parent_type`, `Allegati`.`parent_entity` AS `Allegati.parent_entity`, `Allegati`.`parent_id` AS `Allegati.parent_id`, `Allegati`.`created` AS `Allegati.created`, `Allegati`.`created_by` AS `Allegati.created_by`, `Allegati`.`modified` AS `Allegati.modified`, `Allegati`.`modified_by` AS `Allegati.modified_by`, `Allegati`.`download_count` AS `Allegati.download_count` FROM `nuvrj_content` AS `Article` LEFT JOIN `nuvrj_attachments` AS `Allegati` ON `Article`.`id` = `Allegati`.`parent_id` WHERE `Article`.`state` = 1 AND `Article`.`catid` >= 23 AND `Article`.`catid` <= 27 GROUP BY `Article`.`id` LIMIT 30
)
Stefani@ 23 Jun, 2014
something is happening! :o
're seeing the links?

[attachment=0]Albo pretorio on-line 2014-06-23 23-30-38.png[/attachment]
Stefani@ 23 Jun, 2014
It's working! Thank you Max!
Stefani@ 23 Jun, 2014
Now I'm noticing something else: if there is more than one file attachment in the article, appears in the table only the first.
Max_admin 28 Jun, 2014
Sorry for the delay!

Yes, this is expected since you have set it to "hasOne", please try to change it back to hasMany, clear the "join conditions", fields, order and primary key fields!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Stefani@ 30 Jun, 2014
I tried to change theme, but in that way it doesn't give even the first attachment. What can we do? I do not know whether to give up or insist? I rely on you Max!
Max_admin 30 Jun, 2014
After clearing the fields I mentioned and changing back to "hasMany", can you see any references to "Allegati" in the debug section ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Stefani@ 30 Jun, 2014
Yes, but..
Here's the warning message:
Warning: Invalid argument supplied for foreach() in /web/htdocs/www.stefaniamoscato.it/home/scuolaweb/libraries/cegcore/libs/model.php on line 1005 Warning: Invalid argument supplied for foreach() in /web/htdocs/www.stefaniamoscato.it/home/scuolaweb/libraries/cegcore/libs/model.php on line 773 Warning: Invalid argument supplied for foreach() in /web/htdocs/www.stefaniamoscato.it/home/scuolaweb/libraries/cegcore/libs/model.php on line 773 Warning: Invalid argument supplied for foreach() in /web/htdocs/www.stefaniamoscato.it/home/scuolaweb/libraries/cegcore/libs/model.php on line 773
And here the array:
Array
(
[0] => SELECT `Extension`.`id` AS `Extension.id`, `Extension`.`name` AS `Extension.name` FROM `nuvrj_chronoengine_extensions` AS `Extension` WHERE `Extension`.`enabled` = '1' ORDER BY `Extension`.`ordering` ASC
[1] => SELECT `Connection`.`id` AS `Connection.id`, `Connection`.`title` AS `Connection.title`, `Connection`.`params` AS `Connection.params`, `Connection`.`extras` AS `Connection.extras`, `Connection`.`published` AS `Connection.published` FROM `nuvrj_chronoengine_connections` AS `Connection` WHERE `Connection`.`title` = 'Article' AND `Connection`.`published` = '1'
[2] => SELECT COUNT(*) AS `Article.count` FROM `nuvrj_content` AS `Article` WHERE `Article`.`state` = 1 AND `Article`.`catid` >= 23 AND `Article`.`catid` <= 27
[3] => SELECT `Article`.`id` AS `Article.id`, `Article`.`asset_id` AS `Article.asset_id`, `Article`.`title` AS `Article.title`, `Article`.`alias` AS `Article.alias`, `Article`.`title_alias` AS `Article.title_alias`, `Article`.`introtext` AS `Article.introtext`, `Article`.`fulltext` AS `Article.fulltext`, `Article`.`state` AS `Article.state`, `Article`.`sectionid` AS `Article.sectionid`, `Article`.`mask` AS `Article.mask`, `Article`.`catid` AS `Article.catid`, `Article`.`created` AS `Article.created`, `Article`.`created_by` AS `Article.created_by`, `Article`.`created_by_alias` AS `Article.created_by_alias`, `Article`.`modified` AS `Article.modified`, `Article`.`modified_by` AS `Article.modified_by`, `Article`.`checked_out` AS `Article.checked_out`, `Article`.`checked_out_time` AS `Article.checked_out_time`, `Article`.`publish_up` AS `Article.publish_up`, `Article`.`publish_down` AS `Article.publish_down`, `Article`.`images` AS `Article.images`, `Article`.`urls` AS `Article.urls`, `Article`.`attribs` AS `Article.attribs`, `Article`.`version` AS `Article.version`, `Article`.`parentid` AS `Article.parentid`, `Article`.`ordering` AS `Article.ordering`, `Article`.`metakey` AS `Article.metakey`, `Article`.`metadesc` AS `Article.metadesc`, `Article`.`access` AS `Article.access`, `Article`.`hits` AS `Article.hits`, `Article`.`metadata` AS `Article.metadata`, `Article`.`featured` AS `Article.featured`, `Article`.`language` AS `Article.language`, `Article`.`xreference` AS `Article.xreference` FROM `nuvrj_content` AS `Article` WHERE `Article`.`state` = 1 AND `Article`.`catid` >= 23 AND `Article`.`catid` <= 27 LIMIT 30
[4] => SELECT `Allegati`.`id` AS `Allegati.id`, `Allegati`.`filename` AS `Allegati.filename`, `Allegati`.`filename_sys` AS `Allegati.filename_sys`, `Allegati`.`file_type` AS `Allegati.file_type`, `Allegati`.`file_size` AS `Allegati.file_size`, `Allegati`.`url` AS `Allegati.url`, `Allegati`.`uri_type` AS `Allegati.uri_type`, `Allegati`.`url_valid` AS `Allegati.url_valid`, `Allegati`.`url_relative` AS `Allegati.url_relative`, `Allegati`.`display_name` AS `Allegati.display_name`, `Allegati`.`description` AS `Allegati.description`, `Allegati`.`icon_filename` AS `Allegati.icon_filename`, `Allegati`.`access` AS `Allegati.access`, `Allegati`.`state` AS `Allegati.state`, `Allegati`.`user_field_1` AS `Allegati.user_field_1`, `Allegati`.`user_field_2` AS `Allegati.user_field_2`, `Allegati`.`user_field_3` AS `Allegati.user_field_3`, `Allegati`.`parent_type` AS `Allegati.parent_type`, `Allegati`.`parent_entity` AS `Allegati.parent_entity`, `Allegati`.`parent_id` AS `Allegati.parent_id`, `Allegati`.`created` AS `Allegati.created`, `Allegati`.`created_by` AS `Allegati.created_by`, `Allegati`.`modified` AS `Allegati.modified`, `Allegati`.`modified_by` AS `Allegati.modified_by`, `Allegati`.`download_count` AS `Allegati.download_count` FROM `nuvrj_attachments` AS `Allegati` WHERE `Allegati`.`article_id` IN ('27', '28', '68')
)
Max_admin 01 Jul, 2014
You are using a table list or custom list ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Stefani@ 01 Jul, 2014
Table list with just pagination nav
Max_admin 02 Jul, 2014
1 Likes
Ok! in the "Columns list" please add a new column named "Allegati.data", then in the "PHP Functions" box, please add this line:
Allegati.data:return pr($row);


Now what do you get in this new column added to the table ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 04 Jul, 2014
Answer
1 Likes
Hi Stefania,

The attachments are not loaded, under the "foreign key" field in the "Allegati" model, please enter "parent_id".

Then, go to the php function and change the line to this:

Allegati.data:return implode(",", \GCore\Libs\Arr::getVal($row, array("Allegati", "[n]", "filename"), array()));


I think this should work for you!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Stefani@ 04 Jul, 2014
It's working! Fine! A thousand times thank you Max!
Stefani@ 04 Jul, 2014
Now, the last thing is to create the link to the file to download it.
I tried to do the same way I did for the link to the joomla article, namely:
View linkable -> "Allegati.data"

Links -> Allegati.data:http://www.stefaniamoscato.it/scuolaweb/attachments/article/{Allegati.parent_id}/{Allegati.filename} "target=_blank"

But this time it does not work, why?
Max_admin 08 Jul, 2014
1 Likes
Please try this one instead:

Allegati.data:return implode(",", array_map(function($file){return '<a target="_blank" href="'.$file.'">'.$file.'</a>';}, \GCore\Libs\Arr::getVal($row, array("Allegati", "[n]", "filename"), array())));
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Stefani@ 14 Jul, 2014
Wowwwwwww!
The download files are in a subfolder, then changing your function I got:
Allegati.data:return implode(",", array_map(function($file){return '<a target="_blank" href="attachments/article/{Article.id}/'.$file.'">'.$file.'</a>';}, \GCore\Libs\Arr::getVal($row, array("Allegati", "[n]", "filename"), array())));

it works great!
Thanks Max, thanks to your help I have made ​​a good job!
This topic is locked and no more replies can be posted.