Open preslavrachev opened 3 years ago
hi @preslavrachev Could you provide more context info? Where and when did you see this?
hi @preslavrachev Could you provide more context info? Where and when did you see this?
@raven-chen Everywhere, where a relation is displayed. Say I have an order that has a user. If the user struct has no name attribute, I would get a list of orders, where in the column user, instead of seeing something humanly-readable (e.g. an email, or first namd + last name), I basically see something like the above. The same applies for when attaching a user to an order. I don't see humanly readable identifiers in the dropdowns, but some machine generated concatenation of the struct name and the id (all my model IDs are UUIDs BTW, I have a function that does that upon creation).
does that make sense?
type Sample struct {
Name string //add this field for label
Email string
}
func (s *Sample) BeforeSave() {
if s.Name == "" {
s.Name = s.Email
}
}
type Sample struct { Name string //add this field for label Email string } func (s *Sample) BeforeSave() { if s.Name == "" { s.Name = s.Email } }
Yeah, that's what I did too. If you mark the field as ignored by Gorm, it works, but it's a very obscure way of solving the problem. Relying on an established interface implementation (e.g. Stringer
) would be much cleaner, IMO.
Agreed that adding a "stringer" as an option for resources would be great!
This is an undocumented feature, just add the method Stringify() string to your model, with value receiver, cause pointer receiver won't work.
It's implemented here:
https://github.com/qor/qor/blob/bfbb16ecbc40da17c123aa7cd7211b47caa31391/utils/utils.go#L164
I know that the admin tries to make sense of the field names within the struct types and display the ones that make sense. However, it often falls into a situation, where it literally has no clue. Then, we end up having something like:
What would be the preferred way to hint at QOR Admin which fields to use when displaying a preview?