version: 1
table: users
primary_key: id

fields:
  - integer: id
    required: false
  - keyword: email
    required: true
  - text: fullName
    column: full_name
    required: false
  - uuid: ownerId
    column: owner_id
    required: true
  - enum: tier
    required: true
  - timestamp: createdAt
    column: created_at
    required: false
  - geo: location
    lat: latitude
    lon: longitude
    required: false
  - has_many: orders
    table: orders
    foreign_key: user_id
    primary_key: id
    fields:
      - enum: status
        required: true
      - decimal: total
        required: true
      # An object (has_one) *inside* a nested array — used to exercise the
      # derive's "object under nested" error (its scope can't be expressed).
      - has_one: shipping
        table: shipments
        foreign_key: order_id
        primary_key: order_id
        fields:
          - keyword: carrier
            required: true
  - count: orderCount
    table: orders
    foreign_key: user_id
