Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split ActiveQuery #2

Open
ghost opened this issue Oct 25, 2018 · 4 comments
Open

Split ActiveQuery #2

ghost opened this issue Oct 25, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 25, 2018

@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
Copy link
Member

cebe commented Oct 26, 2018

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 ;)

@SamMousa
Copy link
Contributor

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

@cebe
Copy link
Member

cebe commented Oct 26, 2018

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.

@SamMousa
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants