Welcome Guest, Not a member yet? Register   Sign In
troubles with selecting on joined tables using IgnitedRecord
#1

[eluser]arjo[/eluser]
Hi,

I try to perform a select on joined tables but it won’t work.

This is the code:

Code:
class MDocuments extends IgnitedRecord
{                
    var $table = 'documents';
    var $id_col = 'document_ID';
    
    var $belongs_to = array
    (
        array('table' => 'doctypes', 'name' => 'doctype', 'fk' => 'doctype_ID'),
    );
    
    function getAllDocuments($doctype)
    {
      $this->join_related('doctype', array('name'));    
      $this->where('doctype_name',$doctype);
        return $this->find_all();
    }    
}

produces the following error:

A Database Error Occurred

Error Number: 1054

Unknown column ‘doctype_name’ in ‘where clause’

SELECT `doctype`.`name` AS `doctype_name`, `documents`.* FROM `documents` LEFT JOIN `doctypes` AS `doctype` ON documents.doctype_ID = doctype.doctype_ID WHERE `doctype_name` = ‘public’

I thought the field 'doctype_name' in the query is being created by IgnitedRecord on behalf of the relation as shown in the '$belongs_to' part

Anybody with an idea wat I am doing wrong? (and a solution Smile

Thanks in advance,

Arjo




Theme © iAndrew 2016 - Forum software by © MyBB