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

[12.x] feat: add CanBeOneOfMany support to HasOneThrough #54759

Merged
merged 5 commits into from
Mar 7, 2025

Conversation

calebdw
Copy link
Contributor

@calebdw calebdw commented Feb 24, 2025

Hello!

Closes #54720

This adds *OfMany support to the HasOneThrough relationship:

class Project extends Model
{
    public function latestDeployment(): HasOneThrough
    {
        return $this->deployments()->one()->latestOfMany(); // works!
    }

    public function deployments(): HasManyThrough
    {
        return $this->hasManyThrough(Deployment::class, Environment::class);
    }
}

Thanks!

@@ -131,8 +131,6 @@ public function ofMany($column = 'id', $aggregate = 'MAX', $relation = null)
];
}

$this->addConstraints();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed and adds double constraints:

For example, on existing relations:

image

On the HasOneThrough relation in particular it added a double join clause that prevented the query from even functioning.

@taylorotwell taylorotwell merged commit c5f2a94 into laravel:12.x Mar 7, 2025
37 of 39 checks passed
@taylorotwell
Copy link
Member

Thanks!

@calebdw calebdw deleted the has_one_through_of_many branch March 7, 2025 18:52
@taylorotwell
Copy link
Member

@calebdw would you mind PRing the docs for this?

@calebdw
Copy link
Contributor Author

calebdw commented Mar 12, 2025

Sure thing!

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

Successfully merging this pull request may close these issues.

2 participants