Welcome, Guest
Username: Password: Remember me

TOPIC: [CLOSED] Only one of two filters works

Only one of two filters works 10 Mar 2013 02:25 #6929

  • djod
  • djod's Avatar
  • Offline
  • New Member
  • Posts: 11
  • Thank you received: 1
  • Karma: 0
Hi all

I am trying to filter the contents of a front-end collection. However only the first one will work - the second has no effect.

My database looks like this:


I am trying to filter the Project Targets table on two foreign keys:
  1. Project - this is the parent table of the one I am filtering - this one works okay
  2. Constellation - this is a parent table of the Stars table, which is a foreign key in the Project Targets table - this one does not work

The result (not filtering) can be seen below:


Is it possible to filter a table based upon a FK in a FK table? If not, why does the UI allow me to configure it this way?

Any suggestions welcome.
Clear skies...
David

Amateur astronomer, former programmer and apprentice cook!
The administrator has disabled public write access.

Re: Only one of two filters works 11 Mar 2013 08:46 #6931

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @djod

Looking at the ERD and explanation, it looks like you're traversing 2 tables in the relationship between Project Targets & Constellations, right?

Just to clarify, when you added the 'constellation' field to the filter box, did you select the 'id' field from the table or was it 'name' or another?

Did you enable 'ajax filtering' and any group by in the properties of the filter?

One of the only issues that I've found with the combobox filters is that you cannot have 2 filters based on the same relationship/table - not the issue here. Also, I think this will be changing in the new version.

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Only one of two filters works 11 Mar 2013 09:26 #6932

  • djod
  • djod's Avatar
  • Offline
  • New Member
  • Posts: 11
  • Thank you received: 1
  • Karma: 0
Gez, thanks for the response.

I will address each of your points one at a time.

The key table here is the Project Targets table. This has a foreign key "up" to the Projects table. That relationship is used for one filter (the one that works).

It also has a FK to the Star table (each Project Target has one Star), which in turn has a FK to the Constellation table (Stars exist within Constellations).

When I created the filter combo, I definitely dropped the Constellation.Code field onto the filter, not the ID (I made that mistake when I was doing an original simpler prototype to test out J-Cook ).

There was no grouping or ajax used, since there is nothing appropriate over which to apply that logic in the Constellation table.

Hopefully that is all clear.
Clear skies...
David

Amateur astronomer, former programmer and apprentice cook!
The administrator has disabled public write access.

Re: Only one of two filters works 29 Mar 2013 00:38 #7014

  • djod
  • djod's Avatar
  • Offline
  • New Member
  • Posts: 11
  • Thank you received: 1
  • Karma: 0
Hi All

I have (finally) gotten back to this issue.

I had a look at the generated code. In views.projecttargets.tmpl.default_filters.php, the code for the filters is as follows:
<div style="float:left">
	<!-- SELECT : Project > Code  -->
		<div class='filter filter_project'>
			<label class='filter' for="filter_project"><?php echo(JText::_("VARIABLEPROJECTSDATABASE_JSEARCH_PROJECT")); ?> :</label>
			<?php echo JDom::_('html.form.input.select', array(
						'dataKey' => 'filter_project',
						'dataValue' => (string)$this->filters['project']->value,
						'list' => $this->filters['project']->list,
						'labelKey' => 'code',
						'nullLabel' => "VARIABLEPROJECTSDATABASE_FILTER_NULL_PROJECT",
						'submitEventName' => 'onchange'
							));
				?>
		</div>
</div>

<div style="float:left">
	<!-- SELECT : Constellation > Code  -->
		<div class='filter filter_target_constellation'>
			<label class='filter' for="filter_target_constellation"><?php echo(JText::_("VARIABLEPROJECTSDATABASE_JSEARCH_CONSTELLATION")); ?> :</label>
			<?php echo JDom::_('html.form.input.select', array(
						'dataKey' => 'filter_target_constellation',
						'dataValue' => (string)$this->filters['target_constellation']->value,
						'list' => $this->filters['target_constellation']->list,
						'labelKey' => 'code',
						'nullLabel' => "VARIABLEPROJECTSDATABASE_FILTER_NULL_CONSTELLATION",
						'submitEventName' => 'onchange'
							));
				?>
		</div>
</div>

When looking at the model code for the ProjectTargets (models.forms.projecttargets.php) I can see the following for the setting of the two filters:
//WHERE - FILTER : Project
if($this->getState('filter.project') != null)
	$this->addWhere('a.project = '. (int)$this->getState('filter.project'));

//WHERE - FILTER : Code
if($this->getState('filter._target_constellation'))
	$this->addWhere('_target_.constellation = '. $this->_db->Quote($this->getState('filter._target_constellation')));

I am new to PHP and Joomla programming, but the code for the (constellation) Code appears radically different to the code for the Project (code). I would have expected it to perhaps look like this (just based on consistency):
//WHERE - FILTER : Code
if($this->getState('filter._target_constellation'))
	$this->addWhere('_target_.constellation = '. (int)$this->getState('filter._target_constellation'));

I have tried this, plus a number of other variations (read "stabs in the dark"!), without success.

If anybody has any good ideas, they would be most welcome!!
Clear skies...
David

Amateur astronomer, former programmer and apprentice cook!
Last Edit: 29 Mar 2013 00:40 by djod. Reason: Removed spaces in code
The administrator has disabled public write access.
Time to create page: 0.142 seconds

Get Started