public function testFromArray() { $author = new Author(); $author->setFirstName('Jane'); $author->setLastName('Austen'); $author->save(); $books = array(array('Title' => 'Mansfield Park', 'AuthorId' => $author->getId()), array('Title' => 'Pride And PRejudice', 'AuthorId' => $author->getId())); $col = new PropelArrayCollection(); $col->setModel('Book'); $col->fromArray($books); $col->save(); $nbBooks = PropelQuery::from('Book')->count(); $this->assertEquals(6, $nbBooks); $booksByJane = PropelQuery::from('Book b')->join('b.Author a')->where('a.LastName = ?', 'Austen')->count(); $this->assertEquals(2, $booksByJane); }
public function testToArrayDeep() { $author = new Author(); $author->setId(5678); $author->setFirstName('George'); $author->setLastName('Byron'); $book = new Book(); $book->setId(9012); $book->setTitle('Don Juan'); $book->setISBN('0140422161'); $book->setPrice(12.99); $book->setAuthor($author); $coll = new PropelArrayCollection(); $coll->setModel('Book'); $coll[] = $book->toArray(BasePeer::TYPE_PHPNAME, true, array(), true); $expected = array(array('Id' => 9012, 'Title' => 'Don Juan', 'ISBN' => '0140422161', 'Price' => 12.99, 'PublisherId' => null, 'AuthorId' => 5678, 'Author' => array('Id' => 5678, 'FirstName' => 'George', 'LastName' => 'Byron', 'Email' => null, 'Age' => null, 'Books' => array('Book_0' => '*RECURSION*')))); $this->assertEquals($expected, $coll->toArray()); }