0

I have a SQL query that joins two tables.

SELECT ot.name, org.name from ayakil_organization as org INNER JOIN ayakil_organization_type as ot ON org.type_id = ot.type_id ORDER BY ot.name ASC

Here ayakil_organization, ayakil_organization_type are two tables.

my resolver class is like below.

$collection = $this->_organizationFactory->create()->getCollection();
$collection->getCollection()->getSelect()
            ->join(
                ['ot' => 'e25_organization_type'],
                'main_table.type_id = ot.type_id',
                array("*")
            )
            ->setOrder('ot.name','ASC');

If i use the collection query like this, i am getting an error.Can anyone help me?

2
  • Do you have any model files for ayakil_organization this table ? Commented Nov 13, 2019 at 7:01
  • yes, both tables are handles by two different modules, each tables have its own models and factory
    – Mujahidh
    Commented Nov 13, 2019 at 7:03

1 Answer 1

5

You can try this..

$this->ayakilOrganizationModel
    ->getCollection()
    ->getSelect()
    ->join(
        ['ot' => 'ayakil_organization_type'],
        'main_table.type_id = ot.type_id',
        array("*")
    )
    ->setOrder('ot.name','ASC');

This will return same query which you want.

Hope this will help you!

9
  • 1
    thank you, i check and accept the answer
    – Mujahidh
    Commented Nov 13, 2019 at 7:07
  • Okay and let me know if you have any query there then :) Commented Nov 13, 2019 at 7:07
  • i am using factory method to get the data like this. $collection = $this->_organizationFactory->create()->getCollection(); Can i used model also with that?
    – Mujahidh
    Commented Nov 13, 2019 at 7:19
  • You can use Factory there. Commented Nov 13, 2019 at 7:20
  • 1
    thanks, I will check :)
    – Mujahidh
    Commented Nov 13, 2019 at 7:21

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.