WhiteOctoberPagerfantaBundle icon indicating copy to clipboard operation
WhiteOctoberPagerfantaBundle copied to clipboard

Single id is not allowed on composite primary key

Open antonioperic opened this issue 8 years ago • 3 comments

Hi, i have problem fetching data with Pagerfanta and composite keys

Here is specification of my table, I am wondering is it possible to use composite keys and pagerfanta?

Thnx

<?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="Bundle\ApiBundle\Entity\Item2Term" table="item2_term" repository-class="Bundle\ApiBundle\Repository\Item2TermRepository">
   <indexes>
     <index name="item2_term_FI_1" columns="item2_id"/>
      <index name="item2_term_FI_2" columns="term_id"/>
      <index name="item2_term_FI_3" columns="sf_guard_user_id"/>
    </indexes>
    <id name="item2" association-key="true"/>
   <id name="term" association-key="true"/>
   <id name="sfGuardUser" association-key="true"/>
   <field name="city" type="string" column="city" length="50" nullable="true"/>
  <one-to-one field="sfGuardUser" target-entity="SfGuardUser">
  <join-columns>
    <join-column name="sf_guard_user_id" referenced-column-name="id"/>
  </join-columns>
</one-to-one>
<one-to-one field="term" target-entity="Term">
  <join-columns>
    <join-column name="term_id" referenced-column-name="id"/>
  </join-columns>
</one-to-one>
<one-to-one field="item2" target-entity="Item2">
  <join-columns>
    <join-column name="item2_id" referenced-column-name="id"/>
  </join-columns>
</one-to-one>
  </entity>
</doctrine-mapping>

antonioperic avatar Sep 16 '15 14:09 antonioperic

Could you please explain further your problem?

pablodip avatar Dec 06 '15 16:12 pablodip

@antonioperic So this seems to be a Doctrine issue.

My Fix: Set $fetchJoinCollection of DoctrineORMAdapter to false

Snippet

public function createPagerFromSqlQB(
        OrmQueryBuilder $qb,
        $currentPage,
        $resultsPerPage = 10,
        $fetchJoinCollection = true
    ) {
        $adapter = new DoctrineORMAdapter($qb, $fetchJoinCollection);
        $pager = new Pagerfanta($adapter);
        $pager->setMaxPerPage($resultsPerPage);
        $pager->setCurrentPage($currentPage);

        return $pager;
    }

Usage:

public function createPager($currentPage, $numPerPage = 20)
    {
        return $this->pagerFactory->createPagerFromSqlQB(
            $this->membersAclRolesRepository->getAclMembersQB(),
            $currentPage,
            $numPerPage,
            false
        );
    }

flawal avatar Jan 14 '16 00:01 flawal

thnx

antonioperic avatar Jan 14 '16 01:01 antonioperic