edgedb / easy-edgedb

An illustrated textbook designed to be a one-stop shop for learning EdgeDB
https://www.edgedb.com/easy-edgedb
69 stars 36 forks source link

[Chapter 8] Can't create Crewman without a name #110

Closed erlonbie closed 11 months ago

erlonbie commented 1 year ago

Since Crewman inherites from HasNumber and Person, and Person has a required delegated property, it would make sense to be needed when in inserting a new Crewman (figure 1), but the tutorial tells us that it doesn't need a name (figure 2).

Am I doing something wrong? I'm pretty sure I followed every step of the guide.

image

image

Im using:

My default schema:

module default {

  global time := assert_single((select Time));

  abstract type Person {
    required name: str {
      delegated constraint exclusive;
    }
    multi places_visited: Place;
    lover: Person;
    strength: int16;
  }

  abstract type Place {
    required name: str {
        delegated constraint exclusive;
    };
    modern_name: str;
    important_places: array<str>;
  }

  type City extending Place;

  type Country extending Place;

  scalar type Class extending enum<Rogue, Mystic, Merchant>;

  type NPC extending Person {
    age: HumanAge;
  }

  type PC extending Person {
    required class: Class;
  }

  type Vampire extending Person {
    age: int16;
    multi slaves: MinorVampire;
  }

  scalar type HumanAge extending int16 {
    constraint max_value(120);
  }

  scalar type SleepState extending enum <Asleep, Awake>;

  type Time {
    required clock: str;
    property clock_time := <cal::local_time>.clock;
    property hour := .clock[0:2];
    property vampires_are := SleepState.Asleep if <int16>.hour > 7 and <int16>.hour < 19
      else SleepState.Awake;
  }

  type MinorVampire extending Person {
    #required master: Vampire;
  }

  type Castle extending Place {
      doors: array<int16>;
  }

  type OtherPlace extending Place;

  abstract type HasNumber {
    required number: int16;
  }

  type Crewman extending HasNumber, Person {
  }

  scalar type Rank extending enum<Captain, FirstMate, SecondMate, Cook>;

  type Sailor extending Person {
    rank: Rank;
  }

  type Ship {
    required name: str;
    multi sailors: Sailor;
    multi crew: Crewman;
  }

}
Dhghomon commented 1 year ago

Sorry, the book is under construction right now and part of it was making name required for Person, which makes it required for Crewman as well. Must have pushed that change to main before making the current changes to Crewman which you can see on this branch that I'm currently working on:

https://github.com/edgedb/easy-edgedb/blob/self-review/chapter8/index.md

Now it automatically assigns them a name so the insert still doesn't need to specify a name but they receive one anyway:

type Crewman extending HasNumber, Person { overloaded name: str { default := 'Crewman ' ++ .number; } }

If you don't mind working on a branch as opposed to the shiny final product I would recommend moving to that since I am doing a lot of tying up loose ends together and adding extra info.

erlonbie commented 1 year ago

Thanks for the response, foremost I just wanted to make sure I wasn't mistaking anything. I'll check the self-review branch as well.

Dhghomon commented 11 months ago

The self-review branch is merged so will close this now.