group.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "code.osinet.fr/fgm/entdemo/ent/group"
  7. "github.com/facebookincubator/ent/dialect/sql"
  8. )
  9. // Group is the model entity for the Group schema.
  10. type Group struct {
  11. config `json:"-"`
  12. // ID of the ent.
  13. ID int `json:"id,omitempty"`
  14. // Name holds the value of the "name" field.
  15. Name string `json:"name,omitempty"`
  16. // Edges holds the relations/edges for other nodes in the graph.
  17. // The values are being populated by the GroupQuery when eager-loading is set.
  18. Edges GroupEdges `json:"edges"`
  19. }
  20. // GroupEdges holds the relations/edges for other nodes in the graph.
  21. type GroupEdges struct {
  22. // Users holds the value of the users edge.
  23. Users []*User
  24. // loadedTypes holds the information for reporting if a
  25. // type was loaded (or requested) in eager-loading or not.
  26. loadedTypes [1]bool
  27. }
  28. // UsersOrErr returns the Users value or an error if the edge
  29. // was not loaded in eager-loading.
  30. func (e GroupEdges) UsersOrErr() ([]*User, error) {
  31. if e.loadedTypes[0] {
  32. return e.Users, nil
  33. }
  34. return nil, &NotLoadedError{edge: "users"}
  35. }
  36. // scanValues returns the types for scanning values from sql.Rows.
  37. func (*Group) scanValues() []interface{} {
  38. return []interface{}{
  39. &sql.NullInt64{}, // id
  40. &sql.NullString{}, // name
  41. }
  42. }
  43. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  44. // to the Group fields.
  45. func (gr *Group) assignValues(values ...interface{}) error {
  46. if m, n := len(values), len(group.Columns); m < n {
  47. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  48. }
  49. value, ok := values[0].(*sql.NullInt64)
  50. if !ok {
  51. return fmt.Errorf("unexpected type %T for field id", value)
  52. }
  53. gr.ID = int(value.Int64)
  54. values = values[1:]
  55. if value, ok := values[0].(*sql.NullString); !ok {
  56. return fmt.Errorf("unexpected type %T for field name", values[0])
  57. } else if value.Valid {
  58. gr.Name = value.String
  59. }
  60. return nil
  61. }
  62. // QueryUsers queries the users edge of the Group.
  63. func (gr *Group) QueryUsers() *UserQuery {
  64. return (&GroupClient{config: gr.config}).QueryUsers(gr)
  65. }
  66. // Update returns a builder for updating this Group.
  67. // Note that, you need to call Group.Unwrap() before calling this method, if this Group
  68. // was returned from a transaction, and the transaction was committed or rolled back.
  69. func (gr *Group) Update() *GroupUpdateOne {
  70. return (&GroupClient{config: gr.config}).UpdateOne(gr)
  71. }
  72. // Unwrap unwraps the entity that was returned from a transaction after it was closed,
  73. // so that all next queries will be executed through the driver which created the transaction.
  74. func (gr *Group) Unwrap() *Group {
  75. tx, ok := gr.config.driver.(*txDriver)
  76. if !ok {
  77. panic("ent: Group is not a transactional entity")
  78. }
  79. gr.config.driver = tx.drv
  80. return gr
  81. }
  82. // String implements the fmt.Stringer.
  83. func (gr *Group) String() string {
  84. var builder strings.Builder
  85. builder.WriteString("Group(")
  86. builder.WriteString(fmt.Sprintf("id=%v", gr.ID))
  87. builder.WriteString(", name=")
  88. builder.WriteString(gr.Name)
  89. builder.WriteByte(')')
  90. return builder.String()
  91. }
  92. // Groups is a parsable slice of Group.
  93. type Groups []*Group
  94. func (gr Groups) config(cfg config) {
  95. for _i := range gr {
  96. gr[_i].config = cfg
  97. }
  98. }