function _fetch_related($table, $inflected) { $inflected = ($inflected) ? $inflected[0] : substr($table, 0, -1); if( array_search($table, $this->_belongs_to) !== false ) { $foreign_key = $table . '_id'; $query = $this->db->query('SELECT * FROM ' . $inflected . ' WHERE id = ' . $this->$foreign_key); } else if( array_search($table, $this->_has_many) !== false || array_search($table, $this->_has_one) !== false ) { $query = $this->db->query('SELECT * FROM ' . $table . ' WHERE '. $this->_class_name .'_id = id'); } else if( array_search($table, $this->_has_and_belongs_to_many) !== false ) { $relationship_table = ($this->_table < $table) ? $this->_table . '_' . $table : $table . '_' . $this->_table; $query = $this->db->query(' SELECT ' . $table . '.* FROM ' . $table . ' LEFT JOIN ' . $relationship_table . ' ON ' . $table . '.id = ' . $inflected . '_id LEFT JOIN ' . $this->_table . ' ON ' . $this->_table . '.id = ' . $this->_class_name . '_id WHERE ' . $this->_table . '.id = ' . $this->id ); } else { return false; } eval('$this->' . $table . ' = $query->result();'); }