I have a Magento 2 collection and I want to JOIN more tables to this collection's select:

public function prepareProductCollection(\Magento\Catalog\Model\ResourceModel\Product\Collection $collection) {
    $query = $collection->getSelect();
    $alias = 'mot';
    $name = 'my_own_table';
    $on = "...";
    $cols = ['col1', 'col2'];
    $query->joinLeft([$alias => $name], $on, $cols);        

How can I get table name with prefix if I have $collection variable only? This case returns table name itself (w/o prefix):


You can use


Even this class is also getting table name with this way. Just look at \Magento\Catalog\Model\ResourceModel\Product\Collection this


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.