SetField sets the value of a field with the given name. It returns an error if the field is not defined in the schema, or if the type mismatched the field type.
(name string, value ent.Value)
| 14805 | // the field is not defined in the schema, or if the type mismatched the field |
| 14806 | // type. |
| 14807 | func (m *UserMutation) SetField(name string, value ent.Value) error { |
| 14808 | switch name { |
| 14809 | case user.FieldEmail: |
| 14810 | v, ok := value.(string) |
| 14811 | if !ok { |
| 14812 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 14813 | } |
| 14814 | m.SetEmail(v) |
| 14815 | return nil |
| 14816 | case user.FieldCreatedAt: |
| 14817 | v, ok := value.(time.Time) |
| 14818 | if !ok { |
| 14819 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 14820 | } |
| 14821 | m.SetCreatedAt(v) |
| 14822 | return nil |
| 14823 | case user.FieldUpdatedAt: |
| 14824 | v, ok := value.(time.Time) |
| 14825 | if !ok { |
| 14826 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 14827 | } |
| 14828 | m.SetUpdatedAt(v) |
| 14829 | return nil |
| 14830 | case user.FieldHasRestrictedAccess: |
| 14831 | v, ok := value.(bool) |
| 14832 | if !ok { |
| 14833 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 14834 | } |
| 14835 | m.SetHasRestrictedAccess(v) |
| 14836 | return nil |
| 14837 | case user.FieldFirstName: |
| 14838 | v, ok := value.(string) |
| 14839 | if !ok { |
| 14840 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 14841 | } |
| 14842 | m.SetFirstName(v) |
| 14843 | return nil |
| 14844 | case user.FieldLastName: |
| 14845 | v, ok := value.(string) |
| 14846 | if !ok { |
| 14847 | return fmt.Errorf("unexpected type %T for field %s", value, name) |
| 14848 | } |
| 14849 | m.SetLastName(v) |
| 14850 | return nil |
| 14851 | } |
| 14852 | return fmt.Errorf("unknown User field %s", name) |
| 14853 | } |
| 14854 | |
| 14855 | // AddedFields returns all numeric fields that were incremented/decremented during |
| 14856 | // this mutation. |
no test coverage detected