/**
  * Test removing object when FK is part of the composite PK
  */
 public function testRemove_CompositePK()
 {
     BookReaderQuery::create()->deleteAll();
     BookQuery::create()->deleteAll();
     BookOpinionQuery::create()->deleteAll();
     $br = new BookReader();
     $br->setName("TestReader");
     $br->save();
     $b = new Book();
     $b->setTitle("TestBook");
     $b->setISBN("XX-XX-XX-XX");
     $b->save();
     $op = new BookOpinion();
     $op->setBookReader($br);
     $op->setBook($b);
     $op->setRating(10);
     $op->setRecommendToFriend(true);
     $op->save();
     $this->assertEquals(1, BookReaderQuery::create()->count(), '1 BookReader');
     $this->assertEquals(1, BookQuery::create()->count(), '1 Book');
     $this->assertEquals(1, BookOpinionQuery::create()->count(), '1 BookOpinion');
     // make sure everything is loaded correctly (and their relation too)
     $br->reload(true);
     $b->reload(true);
     $op->reload(true);
     $br->getBookOpinions();
     // load the relation
     $b->removeBookOpinion($op);
     $b->save();
     // the Book knows that there is no longer an opinion
     $this->assertEquals(0, count($b->getBookOpinions()), 'Book knows there is no opinion');
     // but not the BookReader
     $this->assertEquals(1, count($br->getBookOpinions()), 'BookReader still thinks it has 1 opinion');
     $br->reload(true);
     // with relations
     $this->assertEquals(0, count($br->getBookOpinions()), 'BookReader now knows the opinion is gone');
     $this->assertEquals(1, BookReaderQuery::create()->count(), '1 BookReader');
     $this->assertEquals(1, BookQuery::create()->count(), '1 Book');
     $this->assertEquals(0, BookOpinionQuery::create()->count(), '0 BookOpinion');
 }
Example #2
0
 public function testGetLeftPhpName()
 {
     $q = AuthorQuery::create()->joinBook();
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertNull($with->getLeftPhpName(), 'A ModelWith initialized from a primary join has a null left phpName');
     $q = AuthorQuery::create('a')->joinBook();
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertNull($with->getLeftPhpName(), 'A ModelWith initialized from a primary join with alias has a null left phpName');
     $q = AuthorQuery::create()->joinBook('b');
     $joins = $q->getJoins();
     $join = $joins['b'];
     $with = new ModelWith($join);
     $this->assertNull($with->getLeftPhpName(), 'A ModelWith initialized from a primary join with alias has a null left phpName');
     $q = AuthorQuery::create()->join('Author.Book')->join('Book.Publisher');
     $joins = $q->getJoins();
     $join = $joins['Publisher'];
     $with = new ModelWith($join);
     $this->assertEquals('Book', $with->getLeftPhpName(), 'A ModelWith uses the previous join relation name as left phpName');
     $q = ReviewQuery::create()->join('Review.Book')->join('Book.Author')->join('Book.Publisher');
     $joins = $q->getJoins();
     $join = $joins['Publisher'];
     $with = new ModelWith($join);
     $this->assertEquals('Book', $with->getLeftPhpName(), 'A ModelWith uses the previous join relation name as left phpName');
     $q = ReviewQuery::create()->join('Review.Book')->join('Book.BookOpinion')->join('BookOpinion.BookReader');
     $joins = $q->getJoins();
     $join = $joins['BookOpinion'];
     $with = new ModelWith($join);
     $this->assertEquals('Book', $with->getLeftPhpName(), 'A ModelWith uses the previous join relation name as left phpName');
     $join = $joins['BookReader'];
     $with = new ModelWith($join);
     $this->assertEquals('BookOpinion', $with->getLeftPhpName(), 'A ModelWith uses the previous join relation name as left phpName');
     $q = BookReaderQuery::create()->join('BookReader.BookOpinion')->join('BookOpinion.Book')->join('Book.Author');
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertEquals('BookOpinion', $with->getLeftPhpName(), 'A ModelWith uses the previous join relation name as related class');
     $join = $joins['Author'];
     $with = new ModelWith($join);
     $this->assertEquals('Book', $with->getLeftPhpName(), 'A ModelWith uses the previous join relation name as left phpName');
     $q = BookSummaryQuery::create()->join('BookSummary.SummarizedBook')->join('SummarizedBook.Author');
     $joins = $q->getJoins();
     $join = $joins['Author'];
     $with = new ModelWith($join);
     $this->assertEquals('SummarizedBook', $with->getLeftPhpName(), 'A ModelWith uses the previous join relation name as left phpName');
 }