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

Preventing lazy loading causes problems with eager loaded constraints #50134

Closed
kirkbushell opened this issue Feb 18, 2024 · 1 comment
Closed

Comments

@kirkbushell
Copy link
Contributor

Laravel Version

10.44.0

PHP Version

8.3

Database Driver & Version

Postgres 15.1 on Mac Ventura M2 13.6.2

Description

Found a really weird bug - took me all day to find it. Basically, if you have the following enabled:

Model::preventLazyLoading(true);

Eager loaded constraints like the following are not applied:

Article::with([
	'comments' => function($query) {
		$query->orderBy('created_at');
		$query->select('id', 'article_id', 'parent_id', 'user_id', 'body', 'created_at');
        }
]};

I checked my query logs, and the order by and select are never applied:

select * from "comments" where "comments"."article_id" in (410)  

Once I turned off prevent lazy loading:

select "id", "article_id", "parent_id", "user_id", "body", "created_at" from "comments" where "comments"."article_id" in (410) order by "created_at" asc 

I don't know why this would be the case, but it's very strange - I'm eager loading the relationship, and just adding constraints.

Steps To Reproduce

Turn off lazy loading:

Model::preventLazyLoading(true);

Now, in any model, constrain the query with any clause - you'll note that the clause is never applied. It appears to be ignoring them.

@kirkbushell
Copy link
Contributor Author

So, turns out this is actually a Livewire 3 issue, closing.

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

No branches or pull requests

1 participant