Skip to content

Detect the cardinality of unique foreign key relationships #802

@aaditmshah-commversion

Description

@aaditmshah-commversion
  1. many to 1 is a non-nullable foreign key.
  2. many to [0..1] is a nullable foreign key.
  3. [0..1] to 1 is a unique non-nullable foreign key.
  4. [0..1] to [0..1] is a unique nullable foreign key.

The cardinality of ref: > relationships should be inferred from the unique, null, and not null constraints.

Table posts {
  // A user may create many posts. A post has only one creator.
  created_by integer [ref: > users.id, not null] // many to 1

  // A user may update many posts. A post might not be updated.
  last_updated_by integer [ref: > users.id, null] // many to [0..1]
}

Table compliance_training_completions {
  // An employee might not have completed the compliance training.
  // A completion record is specific to one employee.
  created_by integer [ref: > employees.id, unique, not null] // [0..1] to 1
}

Table departments {
  // A department may or may not have a manager.
  // An employee can manage at most one department.
  manager_id integer [ref: > employees.id, unique, null] // [0..1] to [0..1]
}

Correct me if I'm wrong. Currently, there's no way to specify the [0..1] to 1 and [0..1] to [0..1] relationships in DBML.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions