0

The below code entry is already in DB, Now I need to add one field to customer id and want to rerun this code via programmatically.

$this->getSelect()->join(
                    ['detail' => $this->getReviewDetailTable()], 'main_table.review_id = detail.review_id', ['detail_id', 'title', 'detail', 'nickname', 'customer_id']
            );

I have created a custom module from for Product Review. In above I have overrides the Magento review collection class, while overriding this part shows error as

You cannot define a correlation name 'detail' more than once

So Now In my override class I have added the one more field, But DB has the entry already. I also need to handle this while updating or overriding in my class so pls provide me a solution

4 Answers 4

1

Check below query

$this->getSelect()->join(
                    ['details' => $this->getReviewDetailTable()], 'main_table.review_id = details.review_id', ['detail_id', 'title', 'detail', 'nickname', 'customer_id']
            );
7
  • What is the difference between the above code and your answer. Please explain
    – Jaisa
    Commented Feb 10, 2018 at 9:22
  • I have change table alias 'detail' to 'detials' Commented Feb 10, 2018 at 9:22
  • My issue is entry is already done in DB. Now I need to write update
    – Jaisa
    Commented Feb 10, 2018 at 9:23
  • It is a core review_detail table, If I change detail as details, It will cause any issues related DB?? whether will it affect any functionality
    – Jaisa
    Commented Feb 10, 2018 at 9:25
  • No, It will not create a any issue. Commented Feb 10, 2018 at 9:26
0

I know this question has an accepted answer but in this case the line parent::_iniselect() is doing reference to

\Magento\Review\Model\ResourceModel\Review\Collection

(the new parent) which extends from:

\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

(the original parent) so you should change it for

\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::_initSelect();

as shown below:

protected function _initSelect()
{
    //parent::_initSelect();
    \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::_initSelect();

    $this->getSelect()->join(
        ['detail' => $this->getReviewDetailTable()],
        'main_table.review_id = detail.review_id',
        ['detail_id', 'title', 'detail', 'nickname', 'customer_id']
    );
}
0

What is happening is that your join is already set. What you could is to check whether the join was already set or not.

Something like this:

try {
    $this->getSelect()->join(
        ['details' => $this->getReviewDetailTable()], 'main_table.review_id = details.review_id',
        ['detail_id', 'title', 'detail', 'nickname', 'customer_id']
    );
} catch (\Exception $e) {
 ...
}

I would change the alias details to something more unique.

0

I tried this solution of yours but am getting an error where it says protectedMethod _initSelect cannot be accessed in public. I am trying to write my stuff after the _initSelect in Magento\SalesRule\Model\ResourceModel\Rule\Collection using after_initSelect. Got any advice?

2
  • This does not provide answer. If you have any question, you can ask as per https://stackoverflow.com/help/how-to-ask
    – Pawan
    Commented Jun 18, 2021 at 3:54
  • @pawan, Noted. Thank you. Created another questionable post for this. Kindly let me know if you can help. magento.stackexchange.com/questions/339946/…
    – Nithin
    Commented Jun 18, 2021 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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