We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Multiple Right Join

    $projects = $this->modelsManager->createBuilder()
    ->from('Companies')
    ->rightJoin('CompToProductAdapter', 'Companies.id = CompToProductAdapter.company_id')
    ->rightJoin('Projects', 'Projects.id = CompToProductAdapter.project_id')
    ->getQuery()
    ->execute();

    This works however I get the Companies model when I really want the Projects Model.  I've tried the following below:
    1.
        ->addFrom('Companies','c','CompToProductAdapter','a','Projects','p')
    2.
        ->from('CompToProductAdapter ')
        ->from('Projects')
    3.
    ->from(array('Projects','CompToProductAdapter','Companies'))

    and many others but I can't get this to work.  Any suggestions?

You need jus to do:

->columns('Companies.*', 'Projects.*')

You will have row object containing Companies and Projects property with models.

here is my live example:


$member = Team::query()
      ->columns([
        "Manager\Models\Team.name",
        "Manager\Models\Team.image",
        "Manager\Models\Team.phone",
        "Manager\Models\Users.email",
        "Manager\Models\Users.username",
        "Manager\Models\Permissions.level",
      ])
      ->innerJoin("Manager\Models\Users","Manager\Models\Team.uid = Manager\Models\Users._")
      ->innerJoin("Manager\Models\Permissions","Manager\Models\Team.uid = Manager\Models\Permissions.uid")
      ->where("Manager\Models\Team.uid = :user:")
      ->bind([
        "user" => $this->rhyno_user->_
      ])
      ->execute();