Skip to content

feat: add Only #7444

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

Closed
wants to merge 3 commits into from
Closed

feat: add Only #7444

wants to merge 3 commits into from

Conversation

mo1ein
Copy link

@mo1ein mo1ein commented May 5, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Introduces a new Only query method (see issue #7411). This method retrieves exactly one record ordered by primary key and returns an error if zero or multiple records match.

User Case Description

GORM previously lacked a built‑in Only operation, forcing users to manually combine First and Count to enforce uniqueness. Many other ORMs provide this feature natively.

@jinzhu
Copy link
Member

jinzhu commented May 21, 2025

thank you for your PR! However, we’d prefer not to add too many “sugar” APIs.

And a better implementation might be using LIMIT 2 to check if there’s more than one record, rather than triggering an additional COUNT query.

thank you

@jinzhu jinzhu closed this May 21, 2025
@mo1ein
Copy link
Author

mo1ein commented May 21, 2025

So shouldn't the issue be closed too?

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