Welcome, Guest
Username: Password: Remember me

TOPIC: Multiple Cross-References in a Table

Multiple Cross-References in a Table 12 Dec 2016 13:43 #14836

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
Hi all,

I have designed a component Project witch included 2 XRef in the main table.


  • A Conference can be managed by one or many Intervenants,
  • A Conference cover one or many Themes

I 've some questions about that because it seems that the Builder do not handle the second Cross-Reference.
- Is that true or it comes from my table design ?
- Do I have to code the second Xref manualy ?
- Has someone experimented something like that ?

Thanks for your share,
Marc
Last Edit: 13 Dec 2016 22:57 by liubov.
The administrator has disabled public write access.

Multiple Cross-References in a Table 13 Dec 2016 22:36 #14847

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
OK, I got it !

Xref (Pivot Table) and Pivots Filters are just awesome ! exceptionnals features ...
I have played with a lot today :) Easy to implement mutiple Xref to the main Table.

- 1 - add the new Relation (FK) you want to associate in the xml definition of the main table.
admin/models/forms/conference.xml
<field name="themes"
	alias="id"
	label="JDPROGRAM_FIELD_LES_THEMES"
	filter="array"
	type="relation"
	multiple="true"
	labelKey="nom"/>

- 2 - add this new Relation into the view
admin/views/conferences/view.html.php
// Load relations in the object
     $model->loadRelations('intervenants');
     $model->loadRelations('themes');

- 3 - add the new PivotModel
admin/models/conferences.php
 		$this->belongsToMany('themes', // name
			'themes', // foreignModelClass
			'id', // localKey
			'id', // foreignKey,
			'coverfields', // pivotModelClass,
			'conference_id', // pivotLocalKey
			'theme_id', // pivotForeignKey
			array('logo', 'nom') // selectFields
		);

- 4 - add the new cells in the collection
admin/views/conferences/tmpl/default_grid.php
// Column title
<th style="text-align:left">
	<?php echo JText::_("JDPROGRAM_FIELD_THEMES"); ?>
</th>
...
// datas displaying images ...
	<td style="text-align:left">
		<?php
		if (isset($row->themes))
		foreach($row->themes as $rel):
                        echo JDom::_('html.fly.file', array(
                            'width' => '38',
                            'height' => '38',
                            'dataObject' => $rel,
                            'dataKey' => 'logo',
                            'indirect' => false,
                            'root' => '[DIR_THEMES_LOGO]'
                            ));
                    endforeach; ?>
		</td>

or
// datas displaying badge name ...
<td style="text-align:left">
	<?php
	if (isset($row->themes))
	foreach($row->themes as $rel):?>
		<div class="badge">
			<?php echo($rel->nom); ?>
		</div>
	<?php endforeach; ?>
</td>
Last Edit: 13 Dec 2016 22:42 by liubov.
The administrator has disabled public write access.

[closed]Multiple Cross-References in a Table 22 Dec 2016 10:27 #14863

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
  • Karma: 22
hi,
I don't know if it was cache troubles, or a feature update, but I now see the 2 XRef of my main Table to drag proper fields in my layouts.
I just had to use F5 (refresh page) to see the Builder buld the second XRef ...
Last Edit: 22 Dec 2016 10:28 by liubov.
The administrator has disabled public write access.
Time to create page: 0.064 seconds

Get Started