2

I'm trying to model a isA relationship with Aqueduct. It is a one-to-one relationship but I need to make the @Relate column the primary key, however I cannot set both a @Relate and @Column tag. What would be the way to do this ?

Let's say I have a "user" table and a "admin" table. An admin is a user with more fields, for example user has an id, email, username and password, and admin has a user_id, access_level, fullname. Fields that are not needed for a regular user.

The way I'm coding this is like this:

class _User
{
  @primaryKey
  int id;

  String email;

  String username;

  String password;

  Admin admin;
}

class _Admin
{
  @Relate(#admin)
  User user;

  int access_level;

  String fullname;
}

But the migration can't be generated because I didn't declare a primary key for admin, and if I try to add @primaryKey or @Column above User user, I get an error that I can't both set Column and Relate metadata.

Thibaut
  • 21
  • 2
  • 2
    It currently isn't supported to allow a foreign key to be a primary key. There are other (arguably better) ways to model this. Easiest way to do this is just add an auto-incrementing primary key to `Admin` and ignore it; using a JSONB (`Document` data type) to store add'l dynamic details about an object; a role table with a many-to-many relationship, etc. – Joe Conway May 13 '19 at 23:17

0 Answers0