1

I have some some tables which are not related and I try to join tables in my query:

$builder = $this->em()->createQueryBuilder();

$builder->select('main')
            ->from($this->getEntityName(), 'main')
            ->leftJoin('\Bundle\Path\To\Article', 'a', 'WITH', 'a.id = main.articleID');

$query = $builder->getQuery();

$query->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);

$paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query);

return [
    'success' => true,
    'total'   => $paginator->count(),
    'data'    => $paginator->getIterator()->getArrayCopy()
];

and I get this message:

Cannot count query which selects two FROM components, cannot make distinction

Anybody could help me with this issue ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Creative crypter
  • 1,348
  • 6
  • 30
  • 67
  • What version of Doctrine DBAL/ORM are you using? – xurshid29 Aug 20 '15 at 18:04
  • Why should the tables NOT be related to each other? Well you can use Native SQL to use an UNION select: http://stackoverflow.com/questions/19112971/how-to-write-union-query-in-doctrine – webDEVILopers Aug 24 '15 at 09:36

1 Answers1

1

There's two options.

Option 1

SELECT t1.name, t2.date FROM table1 t1, table2 t2;

Obviously this would need modifying to meet your SQL statement/code structure, but I hope you get the point.

Option 2

SELECT t1.name, t2.date FROM table1 t1 CROSS JOIN table2 t2;

Hope this helps :). However, in the future can I suggest googling first as this is a popular question.

mfisher91
  • 805
  • 1
  • 8
  • 23