rendered paste body$dir="/code/propelstart/1.2";
// include our projects Propel generated classes
set_include_path($dir."/build/classes/" . PATH_SEPARATOR . get_include_path());
// include Propel
require_once 'propel/Propel.php';
// include project configuration
Propel::init($dir."/build/conf/bookstore-conf.php");
include_once 'bookstore/Author.php';
include_once 'bookstore/Publisher.php';
include_once 'bookstore/Book.php';
$author = new Author();
$author->setFirstName("Leo");
$author->setLastName("Tolstoy");
// note: we don't save this yet
// 2) Create a Publisher (row of 'publisher' table)
$pub = new Publisher();
$pub->setName("Viking Press");
// note: we don't save this yet
// 3) Create a Book (row of 'book' table)
$book = new Book();
$book->setTitle("War & Peace");
$book->setIsbn("0140444173");
$book->setPublisher($pub);
$book->setAuthor($author);
$book->save(); // saves all 3 objects!
ERROR (for some reason setPublisher/setAuthor isn't recognized, defaulting to 0, always):
Fatal error: Uncaught exception 'PropelException' with message 'Unable to execute INSERT statement. [wrapped: Could not execute update [Native Error: Duplicate entry '0' for key 1] [User Info: INSERT INTO publisher (NAME) VALUES ('Viking Press')]]' in /usr/local/propel/runtime/classes/propel/util/BasePeer.php:308
Stack trace:
#0 /code/propelstart/1.2/build/classes/bookstore/om/BasePublisherPeer.php(358): BasePeer::doInsert(Object(Criteria), Object(MySQLConnection))
#1 /code/propelstart/1.2/build/classes/bookstore/om/BasePublisher.php(255): BasePublisherPeer::doInsert(Object(Publisher), Object(MySQLConnection))
#2 /code/propelstart/1.2/build/classes/bookstore/om/BasePublisher.php(225): BasePublisher->doSave(Object(MySQLConnection))
#3 /code/propelstart/1.2/build/classes/bookstore/om/BaseBook.php(391): BasePublisher->save(Object(MySQLConnection))
#4 /code/propelstart/1.2/build/classes/bookstore/om/BaseBook.php(357): BaseBook->doSave(Object(MySQLConnection))
#5 /code/propelstart/1.2/test2.php(31): BaseBook->save()
#6 {main}
in /usr/local/propel/runtime/classes/propel/util/BasePeer.php on line 308
mysql.log (of previous succesful run, still note missing setPublisher/setAuthor):
386 Query SET AUTOCOMMIT=0
386 Query BEGIN
386 Init DB bookstore
386 Query INSERT INTO publisher (NAME) VALUES ('Viking Press')
386 Init DB bookstore
386 Query INSERT INTO author (FIRST_NAME,LAST_NAME) VALUES ('Leo','Tolstoy')
386 Init DB bookstore
386 Query INSERT INTO book (TITLE,ISBN) VALUES ('War & Peace','0140444173')
386 Init DB bookstore
386 Query COMMIT
386 Query SET AUTOCOMMIT=1