books id integer title varchar(50) authors id integer name varchar(50)
class Model_Book extends Orm\Model {
protected static $_properties = array('id', 'title' );
protected static $_has_one = array('author' );
}
class Model_Author extends Orm\Model {
protected static $_properties = array('id', 'name' ) ;
protected static $_has_many = array('books' ) ;
}
// Read book with id=1 $book = Model_Book::find(1); // Dump Book Debug::dump($book);
Variable #1:
object(Model_Book)#14 (6) {
["_is_new":"Orm\Model":private]=>
bool(false)
["_frozen":"Orm\Model":private]=>
bool(false)
["_data":"Orm\Model":private]=>
array(2) {
["id"]=>
string(1) "1"
["title"]=>
string(6) "Book 1"
}
["_original":"Orm\Model":private]=>
array(2) {
["id"]=>
string(1) "1"
["title"]=>
string(6) "Book 1"
}
["_data_relations":"Orm\Model":private]=>
array(0) {
}
["_original_relations":"Orm\Model":private]=>
array(0) {
}
}
// Now dump author
Debug::dump($book->author);
Fuel\Core\Database_Exception [ 1054 ]: Unknown column 't0.book_id' in 'where clause' [ SELECT `t0`.`id` AS `t0_c0`, `t0`.`name` AS `t0_c1` FROM `authors` AS `t0` WHERE `t0`.`book_id` = '1' LIMIT 1 ] COREPATH/classes/database/mysqli/connection.php @ line 193 188 189 $this->trans_errors[] = $this->_connection->errno.': '.$this->_connection->error.' [ '.$sql.' ]'; 190 } 191 else 192 { 193 throw new \Database_Exception($this->_connection->error.' [ '.$sql.' ]', $this->_connection->errno); 194 } 195 } 196 197 if (isset($benchmark)) 198 {
It looks like you're new here. If you want to get involved, click one of these buttons!