我有一个表objekt_history
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="MBS\AllgemeinBundle\Entity\ObjektHistory" table="objekt_history" repository-class="MBS\AllgemeinBundle\Repository\ObjektHistoryRepository">
<indexes>
<index name="id_objekt_objektnummer_fk1_idx" columns="objektnummer"/>
<index name="id_objekt_subunternehmer_fk2_idx" columns="id_subunternehmer"/>
</indexes>
<id name="id" type="integer" column="id">
<generator strategy="IDENTITY"/>
</id>
<field name="datum" type="datetime" column="datum" nullable="false"/>
<field name="typ" type="boolean" column="typ" nullable="false"/>
<field name="outbox" type="boolean" column="outbox" nullable="false"/>
<many-to-one field="objektnummer" target-entity="Objekt">
<join-columns>
<join-column name="objektnummer" referenced-column-name="objektnummer"/>
<join-column name="id_subunternehmer" referenced-column-name="id_subunternehmer"/>
</join-columns>
</many-to-one>
</entity>
</doctrine-mapping>
Objekt表是
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="MBS\AllgemeinBundle\Entity\Objekt" table="objekt" repository-class="MBS\AllgemeinBundle\Repository\ObjektRepository">
<indexes>
<index name="id_subunternehmer_fk1_idx" columns="id_subunternehmer"/>
<index name="id_mbs_filiale_fk2_idx" columns="id_mbs_filiale"/>
</indexes>
<id name="objektnummer" type="integer" column="objektnummer"/>
<id name="idSubunternehmer" association-key="true"/>
<field name="anschrift1" type="string" column="anschrift1" length="45" nullable="true"/>
<field name="anschrift2" type="string" column="anschrift2" length="45" nullable="false"/>
<field name="strasse" type="string" column="strasse" length="45" nullable="false"/>
<field name="plz" type="string" column="plz" length="45" nullable="false"/>
<field name="ort" type="string" column="ort" length="45" nullable="false"/>
<field name="land" type="string" column="land" length="45" nullable="false"/>
<field name="telefon1" type="string" column="telefon1" length="45" nullable="true"/>
<field name="telefon2" type="string" column="telefon2" length="45" nullable="true"/>
<field name="projektstatus" type="boolean" column="projektstatus" nullable="false"/>
<field name="projektstatusvornichtbeauftragt" type="boolean" column="projektstatusvornichtbeauftragt" nullable="false"/>
<field name="erstellungsdatum" type="datetime" column="erstellungsdatum" nullable="true"/>
<field name="startdatum" type="date" column="startdatum" nullable="true"/>
<field name="endedatum" type="date" column="endedatum" nullable="true"/>
<field name="rechnungsnummer" type="string" column="rechnungsnummer" length="45" nullable="true"/>
<field name="rechnungsdatum" type="date" column="rechnungsdatum" nullable="true"/>
<field name="lohnfahrtkosten" type="float" column="lohnfahrtkosten" precision="10" scale="2" nullable="true"/>
<field name="mwst" type="float" column="mwst" precision="10" scale="2" nullable="true"/>
<field name="werktage" type="integer" column="werktage" nullable="false"/>
<field name="portalnutzungsgebuehr" type="float" column="portalnutzungsgebuehr" precision="10" scale="2" nullable="true"/>
<field name="gesperrt" type="boolean" column="gesperrt" nullable="false"/>
<field name="fertigstellungsdatum" type="date" column="fertigstellungsdatum" nullable="true"/>
<field name="rechnungfreigegeben" type="date" column="rechnungfreigegeben" nullable="true"/>
<field name="korrektur" type="boolean" column="korrektur" nullable="false"/>
<field name="archiviert" type="boolean" column="archiviert" nullable="false"/>
<one-to-one field="idSubunternehmer" target-entity="Subunternehmer">
<join-columns>
<join-column name="id_subunternehmer" referenced-column-name="subunternehmernummer"/>
</join-columns>
</one-to-one>
<many-to-one field="idMbsFiliale" target-entity="MbsFiliale">
<join-columns>
<join-column name="id_mbs_filiale" referenced-column-name="filialnummer"/>
</join-columns>
</many-to-one>
</entity>
</doctrine-mapping>
这是我的实体ObjektHistory:
namespace MBS\AllgemeinBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* ObjektHistory
*/
class ObjektHistory
{
/**
* @var \DateTime
*/
private $datum;
/**
* @var boolean
*/
private $typ;
/**
* @var boolean
*/
private $outbox;
/**
* @var integer $uid
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
*/
private $id;
/**
* @var \MBS\AllgemeinBundle\Entity\Objekt
*/
private $idSubunternehmer;
/**
* @var \MBS\AllgemeinBundle\Entity\Objekt
*/
private $objektnummer;
/**
* Set datum
*
* @param \DateTime $datum
* @return ObjektHistory
*/
public function setDatum($datum)
{
$this->datum = $datum;
return $this;
}
/**
* Get datum
*
* @return \DateTime
*/
public function getDatum()
{
return $this->datum;
}
/**
* Set typ
*
* @param boolean $typ
* @return ObjektHistory
*/
public function setTyp($typ)
{
$this->typ = $typ;
return $this;
}
/**
* Get typ
*
* @return boolean
*/
public function getTyp()
{
return $this->typ;
}
/**
* Set outbox
*
* @param boolean $outbox
* @return ObjektHistory
*/
public function setOutbox($outbox)
{
$this->outbox = $outbox;
return $this;
}
/**
* Get outbox
*
* @return boolean
*/
public function getOutbox()
{
return $this->outbox;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set idSubunternehmer
*
* @param \MBS\AllgemeinBundle\Entity\Objekt $idSubunternehmer
* @return ObjektHistory
*/
public function setIdSubunternehmer(\MBS\AllgemeinBundle\Entity\Objekt $idSubunternehmer = null)
{
$this->idSubunternehmer = $idSubunternehmer;
return $this;
}
/**
* Get idSubunternehmer
*
* @return \MBS\AllgemeinBundle\Entity\Objekt
*/
public function getIdSubunternehmer()
{
return $this->idSubunternehmer;
}
/**
* Set objektnummer
*
* @param \MBS\AllgemeinBundle\Entity\Objekt $objektnummer
* @return ObjektHistory
*/
public function setObjektnummer(\MBS\AllgemeinBundle\Entity\Objekt $objektnummer = null)
{
$this->objektnummer = $objektnummer;
return $this;
}
/**
* Get objektnummer
*
* @return \MBS\AllgemeinBundle\Entity\Objekt
*/
public function getObjektnummer()
{
return $this->objektnummer;
}
}
这是我的控制器:
namespace MBS\AllgemeinBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use MBS\AllgemeinBundle\Entity\ObjektHistory;
class DefaultController extends Controller
{
public function indexAction()
{
$securityContext = $this->container->get( 'security.context' );
if( $securityContext->isGranted( 'IS_AUTHENTICATED_FULLY' ) )
{
$em = $this->getDoctrine()->getManager();
$objektHistoryRepo = $em->getRepository( 'MBSAllgemeinBundle:ObjektHistory' )
->findBy(array("typ" =>2) , array('datum' => 'DESC'));
return $this->render(
'MBSAllgemeinBundle:Default:index.html.twig',
array(
"History" => $objektHistoryRepo
)
);
}
else
{
return $this->redirect($this->generateUrl('fos_user_security_login'));
}
}
}
当我尝试使用
在资源库中搜索时- &gt; findBy(数组(&#34; objektnummer&#34; =&gt; 1234567),数组(&#39;数据&#39; =&gt;&#39; DESC&#39;));
我收到了错误
A single-valued association path expression to an entity with a composite primary key is not supported. Explicitly name the components of the composite primary key in the query.
我做错了什么?
答案 0 :(得分:0)
我认为 objektHistory 实体中的ManyToOne关系应该像这样定义:
<many-to-one field="objektnummer" target-entity="Objekt" join-column="objektnummer">
<join-column name="id_subunternehmer" referenced-column-name="objektnummer" />
</many-to-one>
您无需在实体中定义这些索引