Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
4774a789
Commit
4774a789
authored
Feb 27, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some docs for foreign key constraints
parent
e00fe88d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
Object relational mapping - Relations - Foreign key constraints - Constraint actions.php
...ations - Foreign key constraints - Constraint actions.php
+39
-0
Object relational mapping - Relations - Foreign key constraints - Introduction.php
... - Relations - Foreign key constraints - Introduction.php
+29
-0
No files found.
manual/docs/Object relational mapping - Relations - Foreign key constraints - Constraint actions.php
0 → 100644
View file @
4774a789
//CASCADE//:
Delete
or
update
the
row
from
the
parent
table
and
automatically
delete
or
update
the
matching
rows
in
the
child
table
.
Both
ON
DELETE
CASCADE
and
ON
UPDATE
CASCADE
are
supported
.
Between
two
tables
,
you
should
not
define
several
ON
UPDATE
CASCADE
clauses
that
act
on
the
same
column
in
the
parent
table
or
in
the
child
table
.
//SET NULL// :
Delete
or
update
the
row
from
the
parent
table
and
set
the
foreign
key
column
or
columns
in
the
child
table
to
NULL
.
This
is
valid
only
if
the
foreign
key
columns
do
not
have
the
NOT
NULL
qualifier
specified
.
Both
ON
DELETE
SET
NULL
and
ON
UPDATE
SET
NULL
clauses
are
supported
.
//NO ACTION// :
In
standard
SQL
,
NO
ACTION
means
no
action
in
the
sense
that
an
attempt
to
delete
or
update
a
primary
key
value
is
not
allowed
to
proceed
if
there
is
a
related
foreign
key
value
in
the
referenced
table
.
//RESTRICT// :
Rejects
the
delete
or
update
operation
for
the
parent
table
.
NO
ACTION
and
RESTRICT
are
the
same
as
omitting
the
ON
DELETE
or
ON
UPDATE
clause
.
//SET DEFAULT// :
In
the
following
example
we
define
two
classes
,
User
and
Phonenumber
with
their
relation
being
one
-
to
-
many
.
We
also
add
a
foreign
key
constraint
with
onDelete
cascade
action
.
<
code
type
=
'php'
>
class
User
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
'Phonenumber'
,
'Phonenumber.user_id'
,
array
(
'onDelete'
=>
'cascade'
));
}
public
function
setTableDefition
()
{
$this
->
hasColumn
(
'name'
,
'string'
,
50
);
$this
->
hasColumn
(
'loginname'
,
'string'
,
20
);
$this
->
hasColumn
(
'password'
,
'string'
,
16
);
}
}
class
Phonenumber
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'phonenumber'
,
'string'
,
50
);
$this
->
hasColumn
(
'user_id'
,
'integer'
);
}
}
</
code
>
manual/docs/Object relational mapping - Relations - Foreign key constraints - Introduction.php
0 → 100644
View file @
4774a789
A
foreign
key
constraint
specifies
that
the
values
in
a
column
(
or
a
group
of
columns
)
must
match
the
values
appearing
in
some
row
of
another
table
.
We
say
this
maintains
the
referential
integrity
between
two
related
tables
.
Say
you
have
the
product
table
that
we
have
used
several
times
already
:
CREATE
TABLE
products
(
product_no
integer
PRIMARY
KEY
,
name
text
,
price
numeric
);
Let
'
s
also
assume
you
have
a
table
storing
orders
of
those
products
.
We
want
to
ensure
that
the
orders
table
only
contains
orders
of
products
that
actually
exist
.
So
we
define
a
foreign
key
constraint
in
the
orders
table
that
references
the
products
table
:
CREATE
TABLE
orders
(
order_id
integer
PRIMARY
KEY
,
product_no
integer
REFERENCES
products
(
product_no
),
quantity
integer
);
Now
it
is
impossible
to
create
orders
with
product_no
entries
that
do
not
appear
in
the
products
table
.
We
say
that
in
this
situation
the
orders
table
is
the
referencing
table
and
the
products
table
is
the
referenced
table
.
Similarly
,
there
are
referencing
and
referenced
columns
.
You
can
also
shorten
the
above
command
to
CREATE
TABLE
orders
(
order_id
integer
PRIMARY
KEY
,
product_no
integer
REFERENCES
products
,
quantity
integer
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment