Example #1
0
 public function testSetterCollectionWithManyToManyModifiedByReferenceWithAnExistingObject()
 {
     // Ensure no data
     BookQuery::create()->deleteAll();
     BookClubListQuery::create()->deleteAll();
     BookListRelQuery::create()->deleteAll();
     $book = new Book();
     $book->setTitle('foo');
     $book->save();
     // The object isn't "new"
     $this->assertFalse($book->isNew());
     $bookClubList = new BookClubList();
     $books = $bookClubList->getBooks();
     // Add the object by reference
     $books[] = $book;
     $bookClubList->setBooks($books);
     $bookClubList->save();
     $this->assertEquals(1, BookQuery::create()->count());
     $this->assertEquals(1, BookListRelQuery::create()->count());
     $this->assertEquals(1, BookClubListQuery::create()->count());
 }
 public function testSetterCollectionReplacesOldObjectsByNewObjects()
 {
     // Ensure no data
     BookQuery::create()->deleteAll();
     BookClubListQuery::create()->deleteAll();
     BookListRelQuery::create()->deleteAll();
     $books = new PropelObjectCollection();
     foreach (array('foo', 'bar') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $bookClubList = new BookClubList();
     $bookClubList->setBooks($books);
     $bookClubList->save();
     $books = $bookClubList->getBooks();
     $this->assertEquals('foo', $books[0]->getTitle());
     $this->assertEquals('bar', $books[1]->getTitle());
     $books = new PropelObjectCollection();
     foreach (array('bam', 'bom') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $bookClubList->setBooks($books);
     $bookClubList->save();
     $books = $bookClubList->getBooks();
     $this->assertEquals('bam', $books[0]->getTitle());
     $this->assertEquals('bom', $books[1]->getTitle());
     $this->assertEquals(1, BookClubListQuery::create()->count());
     $this->assertEquals(2, BookListRelQuery::create()->count());
     $this->assertEquals(4, BookQuery::create()->count());
 }