L
L
LastDragon2013-06-07 15:55:54
Yii
LastDragon, 2013-06-07 15:55:54

How to find out the number of related objects?

class Test extends \CActiveRecord {<br>
    public function relations() {<br>
        return [<br>
            'childs' => [self::HAS_MANY, 'Childs', 'parent_id', 'order' => 'childs.title'],<br>
            ];<br>
    }<br>
}<br>

Question: how to find out the number related to this object childs?
Notes:
  1. I know about self::STATand copy-paste links, but I refuse to believe that such shit code can be the norm.
  2. I found one perversion on SO , but somehow I don’t want to use it ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PaulZi, 2013-06-08
@PaulZi

The number of connections without additional. query can only be found by writing a subquery using the addition of the main query through defaultScope ().
With add. Requests only through count($model->related) or as mentioned above through self::STAT.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question