public function testUseFkQuerySimple()
 {
     $q = BookQuery::create()->useAuthorQuery()->filterByFirstName('Leo')->endUse();
     $q1 = BookQuery::create()->join('Book.Author', Criteria::LEFT_JOIN)->add(AuthorTableMap::FIRST_NAME, 'Leo', Criteria::EQUAL);
     $this->assertTrue($q->equals($q1), 'useFkQuery() translates to a condition on a left join on non-required columns');
     $q = BookSummaryQuery::create()->useSummarizedBookQuery()->filterByTitle('War And Peace')->endUse();
     $q1 = BookSummaryQuery::create()->join('BookSummary.SummarizedBook', Criteria::INNER_JOIN)->add(BookTableMap::TITLE, 'War And Peace', Criteria::EQUAL);
     $this->assertTrue($q->equals($q1), 'useFkQuery() translates to a condition on an inner join on required columns');
 }
示例#2
0
 public function testSetterOneToManyReplacesOldObjectsByNewObjectsWithFkRequired()
 {
     // Ensure no data
     BookSummaryQuery::create()->deleteAll();
     BookQuery::create()->deleteAll();
     $bookSummaries = new ObjectCollection();
     foreach (array('foo', 'bar') as $summary) {
         $s = new BookSummary();
         $s->setSummary($summary);
         $bookSummaries[] = $s;
     }
     $b = new Book();
     $b->setTitle('Hello');
     $b->setBookSummaries($bookSummaries);
     $b->save();
     $bookSummaries = $b->getBookSummaries();
     $this->assertEquals('foo', $bookSummaries[0]->getSummary());
     $this->assertEquals('bar', $bookSummaries[1]->getSummary());
     $bookSummaries = new ObjectCollection();
     foreach (array('bam', 'bom') as $summary) {
         $s = new BookSummary();
         $s->setSummary($summary);
         $bookSummaries[] = $s;
     }
     $b->setBookSummaries($bookSummaries);
     $b->save();
     $bookSummaries = $b->getBookSummaries();
     $this->assertEquals('bam', $bookSummaries[0]->getSummary());
     $this->assertEquals('bom', $bookSummaries[1]->getSummary());
     $this->assertEquals(1, BookQuery::create()->count());
     $this->assertEquals(2, BookSummaryQuery::create()->count());
 }
示例#3
0
 public function testGetRightPhpName()
 {
     $q = AuthorQuery::create()->joinBook();
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertEquals('Book', $with->getRightPhpName(), 'A ModelWith initialized from a primary join has a right phpName');
     $q = AuthorQuery::create('a')->joinBook();
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertEquals('Book', $with->getRightPhpName(), 'A ModelWith initialized from a primary join with alias has a right phpName');
     $q = AuthorQuery::create()->joinBook('b');
     $joins = $q->getJoins();
     $join = $joins['b'];
     $with = new ModelWith($join);
     $this->assertEquals('b', $with->getRightPhpName(), 'A ModelWith initialized from a primary join with alias uses the alias as right phpName');
     $q = AuthorQuery::create()->join('Propel\\Tests\\Bookstore\\Author.Book')->join('Book.Publisher');
     $joins = $q->getJoins();
     $join = $joins['Publisher'];
     $with = new ModelWith($join);
     $this->assertEquals('Publisher', $with->getRightPhpName(), 'A ModelWith has a right phpName even when there are previous joins');
     $q = BookSummaryQuery::create()->join('Propel\\Tests\\Bookstore\\BookSummary.SummarizedBook');
     $joins = $q->getJoins();
     $join = $joins['SummarizedBook'];
     $with = new ModelWith($join);
     $this->assertEquals('SummarizedBook', $with->getRightPhpName(), 'A ModelWith uses the relation name rather than the class phpName when it exists');
     $q = BookSummaryQuery::create()->join('Propel\\Tests\\Bookstore\\BookSummary.SummarizedBook')->join('SummarizedBook.Author');
     $joins = $q->getJoins();
     $join = $joins['Author'];
     $with = new ModelWith($join);
     $this->assertEquals('Author', $with->getRightPhpName(), 'A ModelWith has a right phpName even when there are previous joins with custom relation names');
 }
 public function testRemoveObjectOneToManyWithFkRequired()
 {
     BookSummaryQuery::create()->deleteAll();
     BookQuery::create()->deleteAll();
     $bookSummary = new BookSummary();
     $bookSummary->setSummary('summary Propel Book');
     $bookSummary2 = new BookSummary();
     $bookSummary2->setSummary('summary2 Propel Book');
     $book = new Book();
     $book->setTitle('Propel Book');
     $book->setISBN('01234');
     $book->addBookSummary($bookSummary);
     $book->addBookSummary($bookSummary2);
     $this->assertCount(2, $book->getBookSummaries());
     $book->removeBookSummary($bookSummary);
     $bookSummaries = $book->getBookSummaries();
     $this->assertCount(1, $bookSummaries);
     $this->assertEquals('summary2 Propel Book', $bookSummaries->getFirst()->getSummary());
     $book->save();
     $bookSummary2->save();
     $this->assertEquals(1, BookQuery::create()->count(), 'One Book');
     $this->assertEquals(1, BookSummaryQuery::create()->count(), 'One Summary');
     $this->assertEquals(1, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
     $book->addBookSummary($bookSummary);
     $bookSummary->save();
     $book->save();
     $this->assertEquals(2, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
     $book->removeBookSummary($bookSummary2);
     $book->save();
     $this->assertEquals(1, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
     $this->assertEquals(1, BookSummaryQuery::create()->count(), 'One Book summary because FK is required so book summary is deleted when book is saved');
 }