ent
ent copied to clipboard
Query().Unique(true) includes fields not specified in Select
Uniqueness query includes an id field, which is not specified in the explicit call to select method.
Thank you very much for contributing to Ent by creating an issue! ❤️ To avoid duplicate issues we ask you to check off the following list. -->
- [x] The issue is present in the latest release.
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
SELECT DISTINCT id, name
FROM persons
Expected Behavior 🤔
SELECT DISTINCT name
FROM persons
Steps to Reproduce 🕹
Steps:
- Define a table:
import "entgo.io/ent"
type Person struct {
ent.Schema
}
- Define the columns:
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
func (Person) Fields() []ent.Field {
return []ent.Fields{
field.UUID("id", uuid.UUID{}).Default(uuid.New),
field.String("name"),
}
}
-
Insert 2 persons with the same name.
-
Execute the following query:
people, err := entClient.Person.Query().Unique(true).Select(person.FieldName).All(ctx)
// len(people) should return 1, not 2.
Your Environment 🌎
| Tech | Version |
|---|---|
| Go | 1.22.? |
| Ent | 0.12.3 |
| Database | PostgreSQL |
| Driver | https://github.com/lib/pq |
What about using Scan instead?