Relationships
Relationships define how tables are connected within a database schema. They represent the associations between business entities and help maintain data consistency across your application.
In Qubase, relationships are created visually on the ERD Canvas and are automatically synchronized with the underlying database model.
Before you begin
Before creating relationships, ensure that you have:
- Created a Database Schema
- Created at least two tables
- Defined a Primary Key in the parent table
[!NOTE] A relationship usually connects the Primary Key of one table to a Foreign Key in another table.
Why relationships matter
Relationships help you:
- Connect related data
- Reduce duplicate information
- Maintain data integrity
- Support efficient database queries
- Build scalable database designs
Without relationships, tables become isolated and cannot accurately represent real-world business processes.
Create a relationship
To create a relationship:
- Open the ERD Canvas.
- Select the source table.
- Choose the relationship tool.
- Connect the source table to the target table.
- Configure the relationship properties.
- Save the changes.
The relationship is immediately displayed on the ERD Canvas.
Relationship types
Qubase supports the most common database relationship types.
One-to-One (1:1)
One record in the first table is associated with only one record in the second table.
Example:
User
│
│
▼
ProfileTypical use cases:
- User and Profile
- Employee and ID Card
- Customer and Membership
One-to-Many (1:N)
One record in the parent table can be associated with multiple records in the child table.
Example:
Customer
│
├─────────────► Order
├─────────────► Order
└─────────────► OrderTypical use cases:
- Customer → Orders
- Category → Products
- Department → Employees
Many-to-Many (N:M)
Many records in one table can be associated with many records in another table.
This relationship usually requires a junction table.
Example:
Students
│
▼
Student_Course
▲
│
CoursesTypical use cases:
- Students and Courses
- Users and Roles
- Products and Tags
Foreign Keys
Relationships are implemented using Foreign Keys.
A Foreign Key references the Primary Key of another table.
Example:
Customers
------------
customer_id (PK)
Orders
------------
order_id
customer_id (FK)Qubase automatically validates Foreign Key relationships before generating SQL.
Editing relationships
To edit a relationship:
- Select the relationship line.
- Open the Properties Panel.
- Update the required settings.
- Save the changes.
Depending on your model type, you may be able to modify:
- Relationship name
- Relationship type
- Source table
- Target table
- Delete behavior
- Update behavior
Deleting relationships
To remove a relationship:
- Select the relationship.
- Click Delete.
- Confirm the action.
[!WARNING] Deleting a relationship does not automatically remove the related columns. Review your database design after removing relationships.
Validation
Qubase validates relationships to help prevent common design issues.
Validation may include:
- Missing Primary Keys
- Invalid Foreign Keys
- Circular references
- Duplicate relationships
- Incompatible relationship types
Any validation issues are reported before SQL generation.
Best practices
- Create Primary Keys before Foreign Keys.
- Use meaningful relationship names when required.
- Avoid unnecessary many-to-many relationships.
- Keep relationship lines clear and easy to follow.
- Review relationships before generating SQL.