Data Model with GORM and PostgreSQL

Harry · 22 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

Domain Classes

class Department {
  String name
}
class Student {
  String rollNo; String name; String email
  Department department
  static belongsTo = [department: Department]
}

Constraints

rollNo unique and required; email unique with email format; department required.

Indexes

Index name and email for the search queries; foreign key on department.

Key Points

  • Unique rollNo at DB plus domain level.
  • belongsTo gives cascading behavior.
  • Seed departments before students.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in