Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: Database no...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 3452 of 3799
Post > Topic >>

Re: Database normalization

by gatoelho@[EMAIL PROTECTED] ("Sid 'Neko Tamashii'") May 6, 2008 at 09:33 AM

------=_Part_14252_19566201.1210077228506
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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@[EMAIL PROTECTED]
> wrote:

> Sid 'Neko Tama****i' 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
>

------=_Part_14252_19566201.1210077228506
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

To be more clear:<br><blockquote style="border-left: 1px solid rgb(204,
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"
class="gmail_quote">client:<br>&nbsp; id: {type:
integer}<br><br>users:<br>&nbsp; user_id: {type: integer, primaryKey:true,
foreignTable: client, foreignReference: id}<br>
&nbsp; id: {type: integer}<br><br>profiles:<br>&nbsp; client_id: {type:
integer, primaryKey:true, foreignTable: client, foreignReference:
id}<br>&nbsp; id: {type: integer}<br><br>userprofile:<br>&nbsp; client_id:
{type: integer, primaryKey:true}<br>
&nbsp; user_id: {type: integer, primaryKey:true}<br>&nbsp; profile_id:
{type: integer, primaryKey:true}<br>&nbsp;
_foreignKeys:<br>&nbsp;&nbsp;&nbsp;
fk_user:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreignTable:
users<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
references:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - { local:
client_id, foreign: client_id }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - { local: user_id, foreign: id
}<br>&nbsp;&nbsp;&nbsp; fk_profile:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
foreignTable: profile<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
references:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - { local:
client_id, foreign: client_id
}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - { local: profile_id,
foreign: id }<br></blockquote>
<br>Each client has it&#39;s own profiles and users, and each user has
some profiles<br>The idea is to enforce the value of client_id to be the
same at all moments<br><br><div class="gmail_quote">On Tue, May 6, 2008 at
9:28 AM, Richard Huxton &lt;<a
href="mailto:dev@[EMAIL PROTECTED]
">dev@[EMAIL PROTECTED]
>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204,
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div
class="Ih2E3d">Sid &#39;Neko Tama****i&#39; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204,
204, 204); padding-left: 1ex;">
Is this model (Symfony&#39;s YML based) wrong based on normalization?<br>
<br>
propel:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204,
204, 204); padding-left: 1ex;">
 &nbsp;client:<br>
 &nbsp; &nbsp;client_id: {type: integer}<br>
<br>
 &nbsp;foo:<br>
 &nbsp; &nbsp;client_id: {type: integer, foreignTable: client,
foreignReference: client_id}<br>
 &nbsp; &nbsp;foo_id: {type: integer}<br>
<br>
 &nbsp;bar:<br>
 &nbsp; &nbsp;client_id: {type: integer, foreignTable: client,
foreignReference: client_id}<br>
 &nbsp; &nbsp;bar_id: {type: integer}<br>
</blockquote></blockquote>
<br></div>
Well, assuming the primary-key on these includes both columns - e.g.
(client_id,foo_id)<div class="Ih2E3d"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204,
204, 204); padding-left: 1ex;"><blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
 &nbsp;foobar:<br>
 &nbsp; &nbsp;client_id: {type: integer}<br>
 &nbsp; &nbsp;foo_id: {type: integer}<br>
 &nbsp; &nbsp;bar_id: {type: integer}<br>
 &nbsp; &nbsp;_foreignKeys:<br>
 &nbsp; &nbsp; &nbsp;fk_foo:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;foreignTable: foo<br>
 &nbsp; &nbsp; &nbsp; &nbsp;references:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- { local: client_id, foreign:
client_id }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- { local: foo_id, foreign: foo_id
}<br>
 &nbsp; &nbsp; &nbsp;fk_bar:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;foreignTable: bar<br>
 &nbsp; &nbsp; &nbsp; &nbsp;references:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- { local: client_id, foreign:
client_id }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- { local: bar_id, foreign: bar_id
}<br>
</blockquote></blockquote>
<br></div>
This looks fine (assuming not-null on all columns).<br>
<br>
You could make an argument for an explicit foreign-key for client_id too,
but it&#39;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&#39;ll want the foreign-key of course.<br>

<br>
The one thing I would do is change the names of foo_id, bar_id since
they&#39;re not identifiers by themselves.<br><font color="#888888">
<br>
-- <br>
 &nbsp;Richard Huxton<br>
 &nbsp;Archonet Ltd<br>
</font></blockquote></div><br>

------=_Part_14252_19566201.1210077228506--
 




 3 Posts in Topic:
Database normalization
gatoelho@[EMAIL PROTECTED  2008-05-06 08:06:39 
Re: Database normalization
dev@[EMAIL PROTECTED] (R  2008-05-06 13:28:14 
Re: Database normalization
gatoelho@[EMAIL PROTECTED  2008-05-06 09:33:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:28:21 CST 2008.