ImpoUserC
ImpoUserC

Reputation: 619

Columns connection with an additional column

I have such columns in the database:

User
- int Id
- string Name

Flat
- int Id
- string Describe

The flat has a person who manages it and other residents

I think about this solution:

This is the relationship of ManyToMany with an additional column. In this column will be information if he is a managing person

UserFlat
- int UserId
- int FlatId
- bool Creator

Will this be the right approach?

How should I implement it exactly?

Is it directly as a ManyToMany relation or as a manually created and managed table?

The blockage is that users can belong to only one apartment (in the future, the manager will be able to belong to several apartments), but the remaining people can belong to only one apartment

Or is it a completely different and better solution?

Upvotes: 0

Views: 42

Answers (1)

AsheraH
AsheraH

Reputation: 472

If a user can have only one flat and a flat can have only one manager, you don't need a separate table. This should suffice and will work even if one User can be manager of multiple flats:

    User
- int Id
- string Name
- int FlatId > FK to a Flat

Flat
- int Id
- string Describe
- int ManagerId > FK to a User

Upvotes: 1

Related Questions