yiisoft/active-record

Split ActiveQuery

Opened this issue · 4 comments

@SamMousa commented on Oct 25, 2018, 10:12 AM UTC:

Currently yii\db\ActiveQuery operates in 2 contexts (this is documented in the PHPDoc):

  • Normal
  • Relational

This is a violation of the SRP and I don't think there's a need for it.
For example, ActiveQuery class has a $primaryModel property, and a lot of functions change their behavior based on whether or not it is set.

I think we should split this class up into 2 classes, I realize there's some stuff to figure out, that's what this issue is for :)

This issue was moved by samdark from yiisoft/yii-core#53.

cebe commented

The reason for having it in one class is that you can do $query = Post::find() or $query = $post->getAuthor() and get a query which you can work with in the exact same way.

This is a violation of the SRP and I don't think there's a need for it.

for that reason it is split up into traits that handle the different responsibilities ;)

It doesn't have to be the same class to do that though.

cebe commented

how else provide the same functionality?

If I extend ActiveQuery with a custom query class, I want the same functionality to be provided regardless of whether I get the query from find() or relation.

Ah, didn't think a about extending, let me give it some more thought