Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



99.6k
Accepted
answer

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



1.1k

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

For other fields need a JOIN.

Problem solved.