Problem creating authors in the blog module

edited February 2013 in Bug Reports
Hi!
Using the blog module, an SQL error is thrown while creating a new author:

A Database Error Occurred Error Number: 1064 Errore di sintassi nella query SQL vicino a 'AS name asc' linea 4 SELECT id, IF(display_name = "", fuel_users.email, display_name) AS name FROM (`fuel_blog_users`) LEFT JOIN `fuel_users` ON `fuel_users`.`id` = `fuel_blog_users`.`fuel_user_id` ORDER BY IF(display_name = "", `fuel_users`.`email`, `display_name)` AS name asc Filename: /.../fuel/modules/fuel/core/MY_Model.php Line Number: 1119

I "fixed" this changing the options_list() method in the blog_users_model.php file from this:

function options_list($key = 'fuel_user_id', $val = 'display_name', $where = array(), $order = 'display_name') { if ($key == 'id') { $key = $this->table_name.'.fuel_user_id'; } if ($val == 'display_name') { $val = 'IF(display_name = "", fuel_users.email, display_name) AS name'; } $this->db->join('fuel_users', 'fuel_users.id = fuel_blog_users.fuel_user_id', 'left'); $return = parent::options_list($key, $val, $where, $order); return $return; }

to this:

function options_list($key = 'fuel_user_id', $val = 'display_name', $where = array(), $order = 'display_name') { // if ($key == 'id') // { $key = $this->table_name.'.fuel_user_id'; // } if ($val == 'display_name') { $val = 'IF(display_name = "", fuel_users.email, display_name) AS name'; } $order = 'name ASC, display_name ASC'; $this->db->join('fuel_users', 'fuel_users.id = fuel_blog_users.fuel_user_id', 'left'); $return = parent::options_list($key, $val, $where, $order); return $return; }

forcing $key to be not simply "id" (because it throws another error of "Column: 'id' of field list is ambiguos" and I don't know why the "if" condition is not working - the value of $key is "id", so it should be overwritten...) and forcing the $order clause to be defined, because otherwise CodeIgniter puts in the ORDER BY clause the $val content, and the IF condition seems to be not accepted in that point.
I know it's just a workaround but this way it seems to work :D
Sign In or Register to comment.