Fix in foreignkeyfield

This commit is contained in:
Antonio de la Rosa 2016-09-04 23:32:38 +02:00
parent 86547f8955
commit c30a4a5da1
2 changed files with 62 additions and 1 deletions

View file

@ -0,0 +1,61 @@
<?php
/**
*
* @author Antonio de la Rosa <webmaster@web-t-sys.com>
* @file
* @package Core/ModelExtraMethods
*
*
*/
/**
* A useful method for Webmodel for load an array of rows resulted from a query.
*
* With this method you can load only a row specifyng the model id value using a where sql statement.
*
* @param Webmodel $class The instance of the class used
* @param string $where A where sql statement.
* @param array $arr_select An array where the values are the correspondent fields of the model
* @param boolean $raw_query If true, ForeignKeys will be ignored, if false, the return value will load the relationships specified.
* @param integer $index_id If 0, return only associatives keys, if 1, return numeric keys.
*
*/
function select_to_list_method_class($class, $arr_select=array(), $raw_query=0, $index_id='')
{
$arr_return=array();
if($index_id=='')
{
$index_id=$class->idmodel;
}
$arr_select[]=$index_id;
if(count($arr_select)==1)
{
$arr_select=$class->all_fields();
}
$query=$class->select($arr_select, $raw_query);
while($arr_row=$class->fetch_array($query))
{
$arr_return[]=$arr_row;
}
return $arr_return;
}
?>

View file

@ -41,7 +41,7 @@ class ForeignKeyField extends IntegerField{
$this->quot_close='';
$this->protected=0;
//($name, $value, $model, $field_name, $field_value)
$this->parameters=array($this->related_model, $name_field, $name_field);
$this->parameters=array($this->related_model, $name_field, $this->related_model->idmodel);
}