| From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
|---|---|
| To: | Rick Schumeyer <rschumeyer(at)ieee(dot)org> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: one-to-one schema design question and ORM |
| Date: | 2007-03-09 17:48:23 |
| Message-ID: | 20070309174823.GA21355@wolff.to |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Fri, Mar 09, 2007 at 10:06:52 -0500,
Rick Schumeyer <rschumeyer(at)ieee(dot)org> wrote:
>
> From a business rules perspective:
> Some users are not employees (like an admin user)
> Some employees are not users
>
> I can think of two ways to do this:
>
> 1) a 1-1 relationship where the user table contains a FK to the employee
> table. Since not all users will be employees, the FK will sometimes be
> null.
> In rails, the user class would "belong_to employee" while employee
> "has_one user".
>
> 2) Create a link table that has FKs to both the user and employee
> table. This make sense because I'm not sure that the concept of "there
> might be a linked employee" belongs in the user table. This moves it to
> a separate table designed for that purpose. But then again, it may just
> be a needless extra table.
>
> Would you prefer one solution over the other?
I think you need a linking table to properly represent the business rule
above. You can use unique constraints on each key in the link table,
to enforce a 1 to 1 link for the users that are employees.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ezequias Rodrigues da Rocha | 2007-03-09 17:54:12 | PostgreSQL to Oracle |
| Previous Message | Ezequias Rodrigues da Rocha | 2007-03-09 17:40:10 | Statistics |