public function testForeignKeyUsesRequiredColumns() { $column = $this->getColumnMock('author_id'); $column->expects($this->once())->method('isNotNull')->will($this->returnValue(true)); $table = $this->getTableMock('books'); $table->expects($this->once())->method('getColumn')->with($this->equalTo('author_id'))->will($this->returnValue($column)); $fk = new ForeignKey(); $fk->setTable($table); $fk->addReference('author_id', 'id'); $this->assertTrue($fk->isLocalColumnsRequired()); }
/** * Convenience method to get the default Join Type for a relation. * If the key is required, an INNER JOIN will be returned, else a LEFT JOIN will be suggested, * unless the schema is provided with the DefaultJoin attribute, which overrules the default Join Type * * @param ForeignKey $fk * @return string */ protected function getJoinType(ForeignKey $fk) { if ($defaultJoin = $fk->getDefaultJoin()) { return "'" . $defaultJoin . "'"; } if ($fk->isLocalColumnsRequired()) { return 'Criteria::INNER_JOIN'; } return 'Criteria::LEFT_JOIN'; }