Unix Technical Forum

Database normalization

This is a discussion on Database normalization within the pgsql Sql forums, part of the PostgreSQL category; --> Is this model (Symfony's YML based) wrong based on normalization? propel: > client: > client_id: {type: integer} > > ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-07-2008, 10:19 AM
Sid 'Neko Tamashii'
 
Posts: n/a
Default Database normalization

Is this model (Symfony's YML based) wrong based on normalization?

propel:
> client:
> client_id: {type: integer}
>
> foo:
> client_id: {type: integer, foreignTable: client, foreignReference: client_id}
> foo_id: {type: integer}
>
> bar:
> client_id: {type: integer, foreignTable: client, foreignReference: client_id}
> bar_id: {type: integer}
>
> foobar:
> client_id: {type: integer}
> foo_id: {type: integer}
> bar_id: {type: integer}
> _foreignKeys:
> fk_foo:
> foreignTable: foo
> references:
> - { local: client_id, foreign: client_id }
> - { local: foo_id, foreign: foo_id }
> fk_bar:
> foreignTable: bar
> references:
> - { local: client_id, foreign: client_id }
> - { local: bar_id, foreign: bar_id }
>
>

The full discussion can be found at
http://www.symfony-project.org/forum/index.php/t/12807/

All I want is the best option, but not based in common sense, but in rules,
cause after a lot of discussions I found this way better than the usual one.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-07-2008, 10:19 AM
Richard Huxton
 
Posts: n/a
Default Re: Database normalization

Sid 'Neko Tamashii' wrote:
> Is this model (Symfony's YML based) wrong based on normalization?
>
> propel:
>> client:
>> client_id: {type: integer}
>>
>> foo:
>> client_id: {type: integer, foreignTable: client, foreignReference: client_id}
>> foo_id: {type: integer}
>>
>> bar:
>> client_id: {type: integer, foreignTable: client, foreignReference: client_id}
>> bar_id: {type: integer}


Well, assuming the primary-key on these includes both columns - e.g.
(client_id,foo_id)

>>
>> foobar:
>> client_id: {type: integer}
>> foo_id: {type: integer}
>> bar_id: {type: integer}
>> _foreignKeys:
>> fk_foo:
>> foreignTable: foo
>> references:
>> - { local: client_id, foreign: client_id }
>> - { local: foo_id, foreign: foo_id }
>> fk_bar:
>> foreignTable: bar
>> references:
>> - { local: client_id, foreign: client_id }
>> - { local: bar_id, foreign: bar_id }


This looks fine (assuming not-null on all columns).

You could make an argument for an explicit foreign-key for client_id
too, but it's clearly safe not to have one while the other two
foreign-keys are there. If you allow client_id to be set separately from
foo_id/bar_id then you'll want the foreign-key of course.

The one thing I would do is change the names of foo_id, bar_id since
they're not identifiers by themselves.

--
Richard Huxton
Archonet Ltd

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 10:19 AM
Sid 'Neko Tamashii'
 
Posts: n/a
Default Re: Database normalization

To be more clear:

> client:
> id: {type: integer}
>
> users:
> user_id: {type: integer, primaryKey:true, foreignTable: client,
> foreignReference: id}
> id: {type: integer}
>
> profiles:
> client_id: {type: integer, primaryKey:true, foreignTable: client,
> foreignReference: id}
> id: {type: integer}
>
> userprofile:
> client_id: {type: integer, primaryKey:true}
> user_id: {type: integer, primaryKey:true}
> profile_id: {type: integer, primaryKey:true}
> _foreignKeys:
> fk_user:
> foreignTable: users
> references:
> - { local: client_id, foreign: client_id }
> - { local: user_id, foreign: id }
> fk_profile:
> foreignTable: profile
> references:
> - { local: client_id, foreign: client_id }
> - { local: profile_id, foreign: id }
>


Each client has it's own profiles and users, and each user has some profiles
The idea is to enforce the value of client_id to be the same at all moments

On Tue, May 6, 2008 at 9:28 AM, Richard Huxton <dev@archonet.com> wrote:

> Sid 'Neko Tamashii' wrote:
>
> > Is this model (Symfony's YML based) wrong based on normalization?
> >
> > propel:
> >
> > > client:
> > > client_id: {type: integer}
> > >
> > > foo:
> > > client_id: {type: integer, foreignTable: client, foreignReference:
> > > client_id}
> > > foo_id: {type: integer}
> > >
> > > bar:
> > > client_id: {type: integer, foreignTable: client, foreignReference:
> > > client_id}
> > > bar_id: {type: integer}
> > >

> >

> Well, assuming the primary-key on these includes both columns - e.g.
> (client_id,foo_id)
>
>
> > > foobar:
> > > client_id: {type: integer}
> > > foo_id: {type: integer}
> > > bar_id: {type: integer}
> > > _foreignKeys:
> > > fk_foo:
> > > foreignTable: foo
> > > references:
> > > - { local: client_id, foreign: client_id }
> > > - { local: foo_id, foreign: foo_id }
> > > fk_bar:
> > > foreignTable: bar
> > > references:
> > > - { local: client_id, foreign: client_id }
> > > - { local: bar_id, foreign: bar_id }
> > >

> >

> This looks fine (assuming not-null on all columns).
>
> You could make an argument for an explicit foreign-key for client_id too,
> but it's clearly safe not to have one while the other two foreign-keys are
> there. If you allow client_id to be set separately from foo_id/bar_id then
> you'll want the foreign-key of course.
>
> The one thing I would do is change the names of foo_id, bar_id since
> they're not identifiers by themselves.
>
> --
> Richard Huxton
> Archonet Ltd
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:55 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com