CodeIgniter Forums
How do I address a new column in a "joined" table? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How do I address a new column in a "joined" table? (/showthread.php?tid=44090)



How do I address a new column in a "joined" table? - El Forum - 08-02-2011

[eluser]Grego606[/eluser]
I am trying to add a where() condition. The targeted column is 'micro' in a table called 'songs'.

How do I read and update 'micro'?

I attempted to add 'micro' =>$label->song->micro to the "where" array.

Code:
function label($label_id)
    {
        $label = new Label();
        $label->where(array('id' => $label_id,'micro' =>$label->song->micro));
        
        $label->get();
        
        ...
        ...
I get a php error that says:
Quote:Error Number: 1054

Unknown column '0' in 'where clause'

SELECT bands.* FROM (`bands`) LEFT JOIN `bands_labels` ON bands.id = band_id LEFT JOIN `labels` ON labels.id = label_id WHERE `0` IS NULL AND labels.id = 1 ORDER BY `sort`
The Datamapper file:
Code:
class Label extends DataMapper {
    
    var $has_many = array('band' => 'bands', 'song' => 'songs', 'file' => 'files');

    function Label($condition = array())
    {
        parent::DataMapper($condition);
    }
}