diff --git a/extensions/select_to_list.php b/extensions/select_to_list.php new file mode 100644 index 0000000..d5d82bc --- /dev/null +++ b/extensions/select_to_list.php @@ -0,0 +1,61 @@ + +* @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; + +} + +?> diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index ed5f4bb..973fc05 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -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); }