Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Single id is not allowed on composite primary key #125

Open
antonioperic opened this issue Sep 16, 2015 · 3 comments
Open

Single id is not allowed on composite primary key #125

antonioperic opened this issue Sep 16, 2015 · 3 comments

Comments

@antonioperic
Copy link
Contributor

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>
@pablodip
Copy link
Contributor

pablodip commented Dec 6, 2015

Could you please explain further your problem?

@flawal
Copy link

flawal commented Jan 14, 2016

@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
        );
    }

@antonioperic
Copy link
Contributor Author

thnx

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants