×
This forum has been locked. Please submit new Feature Requests on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues
Foreign key field additional SQL parameters
RATE IT SERVICES, SIA
Navegador Iniciado
Posts: 2
8 años 7 meses antes #1295
por RATE IT SERVICES, SIA
Foreign key field additional SQL parameters Publicado por RATE IT SERVICES, SIA
Hi there!
Would be great if a foreign key field could have additional parameter for select query.
Now we select table, key field and value field ..
But how about extra query? For example, I want to select only those records where certain fields have specific value.
SELECT id, name from #__sometable where otherfield=1 ..
I see that this could be possible with SQL list, but then there's no EMPTY RECORD (like Please select value (0) ) ..
I tried to do so with UNION ..
(SELECT '0' as id, 'Please select' as name from #__sometable LIMIT 1) UNION (SELECT id, name from #__sometable where parentid=0)
But then I get mysql errors when any field has selected that parentid field .. HAVING id='1'
thanks
Would be great if a foreign key field could have additional parameter for select query.
Now we select table, key field and value field ..
But how about extra query? For example, I want to select only those records where certain fields have specific value.
SELECT id, name from #__sometable where otherfield=1 ..
I see that this could be possible with SQL list, but then there's no EMPTY RECORD (like Please select value (0) ) ..
I tried to do so with UNION ..
(SELECT '0' as id, 'Please select' as name from #__sometable LIMIT 1) UNION (SELECT id, name from #__sometable where parentid=0)
But then I get mysql errors when any field has selected that parentid field .. HAVING id='1'
thanks
Por favor, Identificarse o Crear cuenta para unirse a la conversación.
Andres Maeso
Navegador Platino
Posts: 338
8 años 7 meses antes #1296
por Andres Maeso
Andrés Maeso
Customer relations manager at Joomla Component Creator.
Esta dirección de correo electrónico está siendo protegida contra los robots de spam. Necesita tener JavaScript habilitado para poder verlo.
Respuesta de Andres Maeso sobre el tema Foreign key field additional SQL parameters
Hi!
Thanks for your feedback. Sounds like a good idea, let's see if it gets more votes!
Regards,
Andrés.
Thanks for your feedback. Sounds like a good idea, let's see if it gets more votes!
Regards,
Andrés.
Andrés Maeso
Customer relations manager at Joomla Component Creator.
Esta dirección de correo electrónico está siendo protegida contra los robots de spam. Necesita tener JavaScript habilitado para poder verlo.
Por favor, Identificarse o Crear cuenta para unirse a la conversación.
RATE IT SERVICES, SIA
Navegador Iniciado
Posts: 2
8 años 7 meses antes #1297
por RATE IT SERVICES, SIA
Respuesta de RATE IT SERVICES, SIA sobre el tema Foreign key field additional SQL parameters
administrator\models\forms\tablename.xml
add new attribute to field : where="parent_id=0"
administrator\models\fields\foreignkey.php
private $where_extra;
protected function getInput()
{
.......
$this->where_extra = (string) $this->getAttribute('where');
........
if($this->where_extra != '')
{
$query->where($this->where_extra);
}
....
}
works fine for me, it's just annoying to modify all this after rebuild ..
add new attribute to field : where="parent_id=0"
administrator\models\fields\foreignkey.php
private $where_extra;
protected function getInput()
{
.......
$this->where_extra = (string) $this->getAttribute('where');
........
if($this->where_extra != '')
{
$query->where($this->where_extra);
}
....
}
works fine for me, it's just annoying to modify all this after rebuild ..
Por favor, Identificarse o Crear cuenta para unirse a la conversación.
Jeremy Morris
Navegador Iniciado
Posts: 4
8 años 3 meses antes #1399
por Jeremy Morris
Respuesta de Jeremy Morris sobre el tema Foreign key field additional SQL parameters
I have also added a "where" attribute to limit foreignkey results based on a condition.
// If the return is to be limited by condition
$this->where = ( trim ( $this->getAttribute('where') ) <> '' ) ? (string) trim( $this->getAttribute('where') ) : NULL;
.......
// add where filtering, if set
if ( $this->where ) {
$query->where($this->where);
} // end if
I have also found that displaying a completely empty select box is pretty useless so I set empty foreignkey fields to hide.
if ( count( $options ) ) {
$html = JHtml::_('select.genericlist', $options, $this->name, $input_options, 'value', 'text', $value, $this->id);
} else {
$html = '';
$this->hidden = true;
}
An additional attribute, such as "hideempty", could be helpful.
// If the return is to be limited by condition
$this->where = ( trim ( $this->getAttribute('where') ) <> '' ) ? (string) trim( $this->getAttribute('where') ) : NULL;
.......
// add where filtering, if set
if ( $this->where ) {
$query->where($this->where);
} // end if
I have also found that displaying a completely empty select box is pretty useless so I set empty foreignkey fields to hide.
if ( count( $options ) ) {
$html = JHtml::_('select.genericlist', $options, $this->name, $input_options, 'value', 'text', $value, $this->id);
} else {
$html = '';
$this->hidden = true;
}
An additional attribute, such as "hideempty", could be helpful.
Por favor, Identificarse o Crear cuenta para unirse a la conversación.
Tiempo de carga de la página: 0.057 segundos