1

I have below collectionFactory

  $collection = $this->collectionFactory->create()->addFieldToFilter('status', ['neq' => 'Disable']);

  $collection->getSelect()->joinLeft(
        ['ce' => 'customer_entity'], "main_table.user_id = ce.entity_id", [
    'CONCAT(ce.firstname," ", ce.lastname) as user_name',
    'ce.email'
        ]
  )->order('id DESC')->limit(5);

  echo $collection->getSelect()->__toString();
  exit;

Above is working fine.

But when i'm trying to do

  $collection = $this->collectionFactory->create()->addFieldToFilter('status', ['neq' => 'Disable'])->joinLeft(
        ['ce' => 'customer_entity'], "main_table.user_id = ce.entity_id", [
    'CONCAT(ce.firstname," ", ce.lastname) as user_name',
    'ce.email'
        ]
  )->order('id DESC')->limit(5);

It gives error

Call to undefined method Custom\Module\Model\ResourceModel\Post\Collection::joinLeft()

Why there is need to use getSelect()? I think getSelect() will get previous defined collection query. So it will carry forward that on.

We can't to collectionFactory in Single?, we have to get & then proceed further?

1

Collections are an entity specific wrapper for the ORM. If you want to build a query that accesses a table outside the scope of that entity then you have to operate on the collection's underlying select.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.