Welcome Guest, Not a member yet? Register   Sign In
1.7 Active Record Select
#1

[eluser]OES[/eluser]
Hi

I am having a problem with 1.7 select data with the * statement.

Model code.
Code:
function list_news()
{
    $this->db->select('ci_news.*, ci_news_categories.name, ci_users.nick');
    $this->db->join('ci_news_categories','ci_news_categories.categoryID = ci_news.categoryID', 'left');
    $this->db->join('ci_users', 'ci_users.userID = ci_news.posterID', 'left');
        
    $this->db->from('ci_news');
    $this->db->order_by('publishDate', 'ASC');
            
    $query = $this->db->get();
    return $query->result_array();
}

Im getting an error.

Code:
Error Number: 1054

Unknown column 'ci_news.*' in 'field list'

SELECT `ci_news`.`*`, `ci_news_categories`.`name`, `ci_users`.`nick` FROM (`ci_news`) LEFT JOIN `ci_news_categories` ON `ci_news_categories`.`categoryID` = `ci_news`.`categoryID` LEFT JOIN `ci_users` ON `ci_users`.`userID` = `ci_news`.`posterID` ORDER BY `publishDate` ASC

If I edit ci_news to select just one item ie, ci_news.title it works ok. So the * is throwing the error.

To say unknown column ci_news is incorrect.

If I run a simple query.

Code:
function list_news()
{            
    $query = $this->db->get('ci_news');
    return $query->result_array();
}

Getting correct results.

I have looked in bug tracker and cant see if this is a bug or not. But I have used this type of code on a number of CI projects with no issues.

Hope you can advise.
#2

[eluser]AgentPhoenix[/eluser]
There are a few threads where people have brought this up, namely this one where a solution is offered:

http://ellislab.com/forums/viewthread/94808/
#3

[eluser]OES[/eluser]
Thanks for that. Adding FALSE fixed my issue.
#4

[eluser]mycroes[/eluser]
+1 on this issue... I'm especially encountering it with the use of tablename.*, where the query will end up as `tablename`.`*`. Quite sloppy to let this slip into release...
#5

[eluser]mycroes[/eluser]
Also this broke the select_sum function:
$this->db->select_sum('group_permissions.permission', 'permissions');
$this->db->from('group_permissions');
$this->db->join('group_members', 'group_permissions.group_id = group_members.group_id');
$this->db->where('group_members.user_id', $user);
$this->db->where('group_permissions.granted', true);
$this->db->group_by('group_permissions.group_id');

results in:
SELECT `SUM(`group_permissions`.`permission`)` AS permissions FROM (`group_permissions`) JOIN `group_members` ON `group_permissions`.`group_id` = `group_members`.`group_id` WHERE `group_members`.`user_id` = '57' AND `group_permissions`.`granted` = 1 GROUP BY `group_permissions`.`group_id`;

I guess this is fixed with the similar issue reported by someone else... Also when it's fixed I expect my $this->db->select('COUNT(something) AS amount'); to work Smile




Theme © iAndrew 2016 - Forum software by © MyBB