Could someone check if the LOC below are flawless, especially:
- the virtual field
- the associations
teacher_id: integer() or should it be teacher: Teacher.t()
user_id: integer() or should it be user: User.t()
# user.ex
@type t :: %__MODULE__{
id: integer,
email: String.t(),
name: String.t(),
phone: String.t(),
credential: Credential.t(),
teacher_id: integer,
student_id: integer,
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t()
}
schema "users" do
field(:email, :string)
field(:name, :string)
field(:phone, :string)
has_one(:credential, Credential)
belongs_to(:teacher, Teacher)
belongs_to(:student, Student)
timestamps()
end
# credential.ex
@type t :: %__MODULE__{
password: String.t(),
password_hash: String.t(),
user_id: integer,
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t()
}
schema "credentials" do
field(:password_hash, :string)
# Virtual Fields
field(:password, :string, virtual: true)
belongs_to(:user, User)
timestamps()
end
# teacher.ex
@type t :: %__MODULE__{
id: integer,
experience: String.t(),
user: User.t(),
students: [ Student.t() ],
subjects: [ Subject.t() ],
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t()
}
schema "teachers" do
field(:experience, :integer, default: 1)
has_one(:user, User)
has_many(:student, Student)
has_many(:subject, Subject)
timestamps()
end






















