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

Relations use :APR or field from current model?

Hello, is it possible to get the index of the current model:


<?php 
$this->hasOne(
      'id',
      'fastPanel\Content\Models\Page\Locale',
      'page_id',
      [
        'alias'  => 'content',
        'params' => [
          'conditions' =>
            " locale = '" . $translate->getCurrentLang() . "'" .

            " OR locale = '" . $translate->getDefaultLang() . "'" .
            " AND page_id = :APR0" .

            " OR locale = '" . \fastPanel\Translate::FALLBACK . "'" .
            " AND page_id = :APR0"
        ]
      ]
    );

OR

<?php 
$this->hasOne(
      'id',
      'fastPanel\Content\Models\Page\Locale',
      'page_id',
      [
        'alias'  => 'content',
        'params' => [
          'conditions' =>
            " locale = '" . $translate->getCurrentLang() . "'" .

            " OR locale = '" . $translate->getDefaultLang() . "'" .
            " AND fastPanel\\Content\\Models\\Page\\Locale.page_id = fastPanel\\Content\\Models\\Page.id" .

            " OR locale = '" . \fastPanel\Translate::FALLBACK . "'" .
            " AND fastPanel\\Content\\Models\\Page\\Locale.page_id = fastPanel\\Content\\Models\\Page.id"
        ]
      ]
    );

How to pass the value of the current model?



145.0k
Accepted
answer

You would need to add joins etc, this will become really nasty.



2.4k

Get the field "id" is possible as ": APR0:" colon at the start and at the end.

For other fields need a JOIN.

Problem solved.