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
70caab15
Commit
70caab15
authored
Apr 11, 2007
by
meus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed some docs. Mainly substituting " with ' in code examples.
parent
7f68e096
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
140 additions
and
139 deletions
+140
-139
Object relational mapping - Introduction.php
manual/codes/Object relational mapping - Introduction.php
+0
-34
Object relational mapping - Record identifiers - Autoincremented.php
...tional mapping - Record identifiers - Autoincremented.php
+2
-1
Object relational mapping - Record identifiers - Composite.php
...t relational mapping - Record identifiers - Composite.php
+2
-2
Object relational mapping - Record identifiers - Natural.php
...ect relational mapping - Record identifiers - Natural.php
+1
-1
Object relational mapping - Relations - Foreign key associations - One-to-Many, Many-to-One.php
...- Foreign key associations - One-to-Many, Many-to-One.php
+6
-6
Object relational mapping - Relations - Foreign key associations - One-to-One.php
...g - Relations - Foreign key associations - One-to-One.php
+10
-10
Object relational mapping - Relations - Foreign key associations - Tree structure.php
...Relations - Foreign key associations - Tree structure.php
+4
-4
Object relational mapping - Relations - Inheritance - One table many classes.php
...ng - Relations - Inheritance - One table many classes.php
+4
-4
Object relational mapping - Relations - Inheritance - One table one class.php
...pping - Relations - Inheritance - One table one class.php
+4
-4
Object relational mapping - Relations - Join table associations - Many-to-Many.php
... - Relations - Join table associations - Many-to-Many.php
+11
-11
Object relational mapping - Relations - Join table associations - Self-referencing.php
...elations - Join table associations - Self-referencing.php
+4
-4
Object relational mapping - Relations - Relation aliases.php
...ect relational mapping - Relations - Relation aliases.php
+7
-7
Working with objects - Component overview - Connection - Flushing the connection.php
...onent overview - Connection - Flushing the connection.php
+3
-3
Working with objects - Component overview - Connection - Getting a table object.php
...ponent overview - Connection - Getting a table object.php
+2
-2
Working with objects - Component overview - Connection - Querying the database.php
...mponent overview - Connection - Querying the database.php
+2
-2
Working with objects - Component overview - Manager - Managing connections.php
...- Component overview - Manager - Managing connections.php
+3
-3
Working with objects - Component overview - Manager - Opening a new connection.php
...mponent overview - Manager - Opening a new connection.php
+3
-3
Working with objects - Dealing with relations - Creating related records.php
...s - Dealing with relations - Creating related records.php
+2
-2
Working with objects - Dealing with relations - Retrieving related records.php
...- Dealing with relations - Retrieving related records.php
+2
-2
Working with objects - Dealing with relations - Updating related records.php
...s - Dealing with relations - Updating related records.php
+2
-2
Object relational mapping - Introduction.php
manual/docs/Object relational mapping - Introduction.php
+40
-6
Object relational mapping - Relations - Inheritance - Column aggregation.php
...apping - Relations - Inheritance - Column aggregation.php
+26
-26
No files found.
manual/codes/Object relational mapping - Introduction.php
deleted
100644 → 0
View file @
7f68e096
<?php
class
Email
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
// setting custom table name:
$this
->
setTableName
(
'emails'
);
$this
->
hasColumn
(
"address"
,
// name of the column
"string"
,
// column type
"200"
,
// column length
array
(
"notblank"
=>
true
,
"email"
=>
true
// validators / constraints
)
);
$this
->
hasColumn
(
"address2"
,
// name of the column
"string"
,
// column type
"200"
,
// column length
// validators / constraints without arguments can be
// specified also as as string with | separator
"notblank|email"
);
// Doctrine even supports the following format for
// validators / constraints which have no arguments:
$this
->
hasColumn
(
"address3"
,
// name of the column
"string"
,
// column type
"200"
,
// column length
array
(
"notblank"
,
"email"
)
);
}
}
?>
manual/codes/Object relational mapping - Record identifiers - Autoincremented.php
View file @
70caab15
<?php
class
User
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"uid"
,
"integer"
,
20
,
"primary|autoincrement"
);
$this
->
hasColumn
(
'uid'
,
'integer'
,
20
,
'primary|autoincrement'
);
}
}
?>
manual/codes/Object relational mapping - Record identifiers - Composite.php
View file @
70caab15
<?php
class
Groupuser
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"user_id"
,
"integer"
,
20
,
"primary"
);
$this
->
hasColumn
(
"group_id"
,
"integer"
,
20
,
"primary"
);
$this
->
hasColumn
(
'user_id'
,
'integer'
,
20
,
'primary'
);
$this
->
hasColumn
(
'group_id'
,
'integer'
,
20
,
'primary'
);
}
}
?>
manual/codes/Object relational mapping - Record identifiers - Natural.php
View file @
70caab15
<?php
class
User
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
200
,
"primary"
);
$this
->
hasColumn
(
'name'
,
'string'
,
200
,
'primary'
);
}
}
?>
manual/codes/Object relational mapping - Relations - Foreign key associations - One-to-Many, Many-to-One.php
View file @
70caab15
<?php
class
User
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
ownsMany
(
"Phonenumber"
,
"Phonenumber.user_id"
);
$this
->
ownsMany
(
'Phonenumber'
,
'Phonenumber.user_id'
);
}
public
function
setTableDefition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
50
);
$this
->
hasColumn
(
"loginname"
,
"string"
,
20
);
$this
->
hasColumn
(
"password"
,
"string"
,
16
);
$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"
);
$this
->
hasColumn
(
'phonenumber'
,
'string'
,
50
);
$this
->
hasColumn
(
'user_id'
,
'integer'
);
}
}
?>
manual/codes/Object relational mapping - Relations - Foreign key associations - One-to-One.php
View file @
70caab15
<?php
class
User
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasOne
(
"Address"
,
"Address.user_id"
);
$this
->
ownsOne
(
"Email"
,
"User.email_id"
);
$this
->
ownsMany
(
"Phonenumber"
,
"Phonenumber.user_id"
);
$this
->
hasOne
(
'Address'
,
'Address.user_id'
);
$this
->
ownsOne
(
'Email'
,
'User.email_id'
);
$this
->
ownsMany
(
'Phonenumber'
,
'Phonenumber.user_id'
);
}
public
function
setTableDefition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
50
);
$this
->
hasColumn
(
"loginname"
,
"string"
,
20
);
$this
->
hasColumn
(
"password"
,
"string"
,
16
);
$this
->
hasColumn
(
'name'
,
'string'
,
50
);
$this
->
hasColumn
(
'loginname'
,
'string'
,
20
);
$this
->
hasColumn
(
'password'
,
'string'
,
16
);
// foreign key column for email ID
$this
->
hasColumn
(
"email_id"
,
"integer"
);
$this
->
hasColumn
(
'email_id'
,
'integer'
);
}
}
class
Email
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"address"
,
"string"
,
150
);
$this
->
hasColumn
(
'address'
,
'string'
,
150
);
}
}
class
Address
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"street"
,
"string"
,
50
);
$this
->
hasColumn
(
"user_id"
,
"integer"
);
$this
->
hasColumn
(
'street'
,
'string'
,
50
);
$this
->
hasColumn
(
'user_id'
,
'integer'
);
}
}
?>
manual/codes/Object relational mapping - Relations - Foreign key associations - Tree structure.php
View file @
70caab15
<?php
class
Task
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasOne
(
"Task as Parent"
,
"Task.parent_id"
);
$this
->
hasMany
(
"Task as Subtask"
,
"Subtask.parent_id"
);
$this
->
hasOne
(
'Task as Parent'
,
'Task.parent_id'
);
$this
->
hasMany
(
'Task as Subtask'
,
'Subtask.parent_id'
);
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
100
);
$this
->
hasColumn
(
"parent_id"
,
"integer"
);
$this
->
hasColumn
(
'name'
,
'string'
,
100
);
$this
->
hasColumn
(
'parent_id'
,
'integer'
);
}
}
?>
manual/codes/Object relational mapping - Relations - Inheritance - One table many classes.php
View file @
70caab15
<?php
class
Entity
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
30
);
$this
->
hasColumn
(
"username"
,
"string"
,
20
);
$this
->
hasColumn
(
"password"
,
"string"
,
16
);
$this
->
hasColumn
(
"created"
,
"integer"
,
11
);
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
$this
->
hasColumn
(
'username'
,
'string'
,
20
);
$this
->
hasColumn
(
'password'
,
'string'
,
16
);
$this
->
hasColumn
(
'created'
,
'integer'
,
11
);
}
}
...
...
manual/codes/Object relational mapping - Relations - Inheritance - One table one class.php
View file @
70caab15
<?php
class
Entity
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
30
);
$this
->
hasColumn
(
"username"
,
"string"
,
20
);
$this
->
hasColumn
(
"password"
,
"string"
,
16
);
$this
->
hasColumn
(
"created"
,
"integer"
,
11
);
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
$this
->
hasColumn
(
'username'
,
'string'
,
20
);
$this
->
hasColumn
(
'password'
,
'string'
,
16
);
$this
->
hasColumn
(
'created'
,
'integer'
,
11
);
}
}
...
...
manual/codes/Object relational mapping - Relations - Join table associations - Many-to-Many.php
View file @
70caab15
<?php
class
User
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
"Group"
,
"Groupuser.group_id"
);
$this
->
hasMany
(
'Group'
,
'Groupuser.group_id'
);
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
30
);
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
}
}
class
Group
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
"User"
,
"Groupuser.user_id"
);
$this
->
hasMany
(
'User'
,
'Groupuser.user_id'
);
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
30
);
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
}
}
class
Groupuser
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"user_id"
,
"integer"
);
$this
->
hasColumn
(
"group_id"
,
"integer"
);
$this
->
hasColumn
(
'user_id'
,
'integer'
);
$this
->
hasColumn
(
'group_id'
,
'integer'
);
}
}
...
...
@@ -28,9 +28,9 @@ class Groupuser extends Doctrine_Record {
$user
=
new
User
();
// add two groups
$user
->
Group
[
0
]
->
name
=
"First Group"
;
$user
->
Group
[
0
]
->
name
=
'First Group'
;
$user
->
Group
[
1
]
->
name
=
"Second Group"
;
$user
->
Group
[
1
]
->
name
=
'Second Group'
;
// save changes into database
$user
->
save
();
...
...
@@ -39,11 +39,11 @@ $user->save();
$user
->
Groupuser
->
delete
();
$groups
=
new
Doctrine_Collection
(
$conn
->
getTable
(
"Group"
));
$groups
=
new
Doctrine_Collection
(
$conn
->
getTable
(
'Group'
));
$groups
[
0
]
->
name
=
"Third Group"
;
$groups
[
0
]
->
name
=
'Third Group'
;
$groups
[
1
]
->
name
=
"Fourth Group"
;
$groups
[
1
]
->
name
=
'Fourth Group'
;
$user
->
Group
[
2
]
=
$groups
[
0
];
// $user will now have 3 groups
...
...
manual/codes/Object relational mapping - Relations - Join table associations - Self-referencing.php
View file @
70caab15
<?php
class
User
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
"User as Friend"
,
"UserReference.user_id-user_id2"
);
$this
->
hasMany
(
'User as Friend'
,
'UserReference.user_id-user_id2'
);
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
30
);
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
}
}
class
UserReference
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"user_id"
,
"integer"
);
$this
->
hasColumn
(
"user_id2"
,
"integer"
);
$this
->
hasColumn
(
'user_id'
,
'integer'
);
$this
->
hasColumn
(
'user_id2'
,
'integer'
);
}
}
?>
manual/codes/Object relational mapping - Relations - Relation aliases.php
View file @
70caab15
<?php
class
Forum_Board
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
100
);
$this
->
hasColumn
(
"description"
,
"string"
,
5000
);
$this
->
hasColumn
(
'name'
,
'string'
,
100
);
$this
->
hasColumn
(
'description'
,
'string'
,
5000
);
}
public
function
setUp
()
{
// notice the 'as' keyword here
$this
->
ownsMany
(
"Forum_Thread as Threads"
,
"Forum_Thread.board_id"
);
$this
->
ownsMany
(
'Forum_Thread as Threads'
,
'Forum_Thread.board_id'
);
}
}
class
Forum_Thread
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"board_id"
,
"integer"
,
10
);
$this
->
hasColumn
(
"updated"
,
"integer"
,
10
);
$this
->
hasColumn
(
"closed"
,
"integer"
,
1
);
$this
->
hasColumn
(
'board_id'
,
'integer'
,
10
);
$this
->
hasColumn
(
'updated'
,
'integer'
,
10
);
$this
->
hasColumn
(
'closed'
,
'integer'
,
1
);
}
public
function
setUp
()
{
// notice the 'as' keyword here
$this
->
hasOne
(
"Forum_Board as Board"
,
"Forum_Thread.board_id"
);
$this
->
hasOne
(
'Forum_Board as Board'
,
'Forum_Thread.board_id'
);
}
}
$board
=
new
Board
();
...
...
manual/codes/Working with objects - Component overview - Connection - Flushing the connection.php
View file @
70caab15
<?php
$user
=
new
User
();
$user
->
name
=
"Jack"
;
$user
->
name
=
'Jack'
;
$group
=
$conn
->
create
(
"Group"
);
$group
->
name
=
"Drinking Club"
;
$group
=
$conn
->
create
(
'Group'
);
$group
->
name
=
'Drinking Club'
;
// saves all the changed objects into database
...
...
manual/codes/Working with objects - Component overview - Connection - Getting a table object.php
View file @
70caab15
...
...
@@ -3,9 +3,9 @@ $manager = Doctrine_Manager::getInstance();
// open new connection
$conn
=
$manager
->
openConnection
(
new
PDO
(
"dsn"
,
"username"
,
"password"
));
$conn
=
$manager
->
openConnection
(
new
PDO
(
'dsn'
,
'username'
,
'password'
));
// getting a table object
$table
=
$conn
->
getTable
(
"User"
);
$table
=
$conn
->
getTable
(
'User'
);
?>
manual/codes/Working with objects - Component overview - Connection - Querying the database.php
View file @
70caab15
...
...
@@ -2,7 +2,7 @@
// select all users
$users
=
$conn
->
query
(
"FROM User"
);
$users
=
$conn
->
query
(
'FROM User'
);
// select all users where user email is jackdaniels@drinkmore.info
...
...
@@ -10,5 +10,5 @@ $users = $conn->query("FROM User WHERE User.Email.address = 'jackdaniels@drinkmo
// using prepared statements
$users
=
$conn
->
query
(
"FROM User WHERE User.name = ?"
,
array
(
'Jack'
));
$users
=
$conn
->
query
(
'FROM User WHERE User.name = ?'
,
array
(
'Jack'
));
?>
manual/codes/Working with objects - Component overview - Manager - Managing connections.php
View file @
70caab15
...
...
@@ -5,15 +5,15 @@ $manager = Doctrine_Manager::getInstance();
// open first connection
$conn
=
$manager
->
openConnection
(
new
PDO
(
"dsn"
,
"username"
,
"password"
),
"connection 1"
);
$conn
=
$manager
->
openConnection
(
new
PDO
(
'dsn'
,
'username'
,
'password'
),
'connection 1'
);
// open second connection
$conn2
=
$manager
->
openConnection
(
new
PDO
(
"dsn2"
,
"username2"
,
"password2"
),
"connection 2"
);
$conn2
=
$manager
->
openConnection
(
new
PDO
(
'dsn2'
,
'username2'
,
'password2'
),
'connection 2'
);
$manager
->
getCurrentConnection
();
// $conn2
$manager
->
setCurrentConnection
(
"connection 1"
);
$manager
->
setCurrentConnection
(
'connection 1'
);
$manager
->
getCurrentConnection
();
// $conn
...
...
manual/codes/Working with objects - Component overview - Manager - Opening a new connection.php
View file @
70caab15
...
...
@@ -6,13 +6,13 @@ $manager = Doctrine_Manager::getInstance();
// Doctrine_Connection
// a script may have multiple open connections
// (= multiple database connections)
$dbh
=
new
PDO
(
"dsn"
,
"username"
,
"password"
);
$dbh
=
new
PDO
(
'dsn'
,
'username'
,
'password'
);
$conn
=
$manager
->
openConnection
();
// or if you want to use Doctrine Doctrine_Db and its
// performance monitoring capabilities
$dsn
=
"schema://username:password@dsn/dbname"
;
$dbh
=
Doctrine_Db
::
getConnection
(
$dsn
);
$dsn
=
'schema://username:password@dsn/dbname'
;
$dbh
=
Doctrine_Db
::
getConnection
(
$dsn
);
$conn
=
$manager
->
openConnection
();
?>
manual/codes/Working with objects - Dealing with relations - Creating related records.php
View file @
70caab15
...
...
@@ -2,13 +2,13 @@
// NOTE: related record have always the first letter in uppercase
$email
=
$user
->
Email
;
$email
->
address
=
"jackdaniels@drinkmore.info"
;
$email
->
address
=
'jackdaniels@drinkmore.info'
;
$user
->
save
();
// alternative:
$user
->
Email
->
address
=
"jackdaniels@drinkmore.info"
;
$user
->
Email
->
address
=
'jackdaniels@drinkmore.info'
;
$user
->
save
();
?>
manual/codes/Working with objects - Dealing with relations - Retrieving related records.php
View file @
70caab15
<?php
print
$user
->
Email
[
"address"
];
print
$user
->
Email
[
'address'
];
print
$user
->
Phonenumber
[
0
]
->
phonenumber
;
print
$user
->
Group
[
0
]
->
get
(
"name"
)
;
print
$user
->
Group
[
0
]
->
name
;
?>
manual/codes/Working with objects - Dealing with relations - Updating related records.php
View file @
70caab15
<?php
$user
->
Email
[
"address"
]
=
"koskenkorva@drinkmore.info"
;
$user
->
Email
[
'address'
]
=
'koskenkorva@drinkmore.info'
;
$user
->
Phonenumber
[
0
]
->
phonenumber
=
"123123"
;
$user
->
Phonenumber
[
0
]
->
phonenumber
=
'123123'
;
$user
->
save
();
...
...
manual/docs/Object relational mapping - Introduction.php
View file @
70caab15
Setting
up
a
table
definition
in
doctrine
is
done
by
using
hasColumn
method
calls
inside
setTableDefinition
method
.
Doctrine_Record
::
hasColumn
()
takes
4
arguments
:<
br
\
>
Doctrine_Record
::
hasColumn
()
takes
4
arguments
:
1.
[
<
b
class
="
title
">column name</b>] <br />
2. [<b class="
title
">column type</b>] <br />
3. [<b class="
title
">column length</b>] <br />
4. [<b class="
title
">column constraints and validators</b>]
# **column name**
# **column type**
# **column length**
# **column constraints and validators**
<
code
type
=
'php'
>
class
Email
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
// setting custom table name:
$this
->
setTableName
(
'emails'
);
$this
->
hasColumn
(
'address'
,
// name of the column
'string'
,
// column type
'200'
,
// column length
array
(
'notblank'
=>
true
,
'email'
=>
true
// validators / constraints
)
);
$this
->
hasColumn
(
'address2'
,
// name of the column
'string'
,
// column type
'200'
,
// column length
// validators / constraints without arguments can be
// specified also as as string with | separator
'notblank|email'
);
// Doctrine even supports the following format for
// validators / constraints which have no arguments:
$this
->
hasColumn
(
'address3'
,
// name of the column
'string'
,
// column type
'200'
,
// column length
array
(
'notblank'
,
'email'
)
);
}
}
</
code
>
manual/docs/Object relational mapping - Relations - Inheritance - Column aggregation.php
View file @
70caab15
...
...
@@ -4,83 +4,83 @@ The entity table has a column called 'type' which tells whether an entity is a g
The
only
thing
we
have
to
do
is
to
create
3
records
(
the
same
as
before
)
and
add
call
the
Doctrine_Table
::
setInheritanceMap
()
method
inside
the
setUp
()
method
.
<
code
type
=
"php"
>
<
code
type
=
'php'
>
class
Entity
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
30
);
$this
->
hasColumn
(
"username"
,
"string"
,
20
);
$this
->
hasColumn
(
"password"
,
"string"
,
16
);
$this
->
hasColumn
(
"created"
,
"integer"
,
11
);
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
$this
->
hasColumn
(
'username'
,
'string'
,
20
);
$this
->
hasColumn
(
'password'
,
'string'
,
16
);
$this
->
hasColumn
(
'created'
,
'integer'
,
11
);
// this column is used for column
// aggregation inheritance
$this
->
hasColumn
(
"type"
,
"integer"
,
11
);
$this
->
hasColumn
(
'type'
,
'integer'
,
11
);
}
}
class
User
extends
Entity
{
public
function
setUp
()
{
$this
->
setInheritanceMap
(
array
(
"type"
=>
1
));
$this
->
setInheritanceMap
(
array
(
'type'
=>
1
));
}
}
class
Group
extends
Entity
{
public
function
setUp
()
{
$this
->
setInheritanceMap
(
array
(
"type"
=>
2
));
$this
->
setInheritanceMap
(
array
(
'type'
=>
2
));
}
}
</
code
>
If
we
want
to
be
able
to
fetch
a
record
from
the
Entity
table
and
automatically
get
a
User
record
if
the
Entity
we
fetched
is
a
user
we
have
to
do
set
the
subclasses
option
in
the
parent
class
.
The
adjusted
example
:
<
code
type
=
"php"
>
<
code
type
=
'php'
>
class
Entity
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
30
);
$this
->
hasColumn
(
"username"
,
"string"
,
20
);
$this
->
hasColumn
(
"password"
,
"string"
,
16
);
$this
->
hasColumn
(
"created"
,
"integer"
,
11
);
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
$this
->
hasColumn
(
'username'
,
'string'
,
20
);
$this
->
hasColumn
(
'password'
,
'string'
,
16
);
$this
->
hasColumn
(
'created'
,
'integer'
,
11
);
// this column is used for column
// aggregation inheritance
$this
->
hasColumn
(
"type"
,
"integer"
,
11
);
$this
->
option
(
"subclasses"
,
array
(
"User"
,
"Group"
);
$this
->
hasColumn
(
'type'
,
'integer'
,
11
);
$this
->
option
(
'subclasses'
,
array
(
'User'
,
'Group'
);
}
}
class
User
extends
Entity
{
public
function
setUp
()
{
$this
->
setInheritanceMap
(
array
(
"type"
=>
1
));
$this
->
setInheritanceMap
(
array
(
'type'
=>
1
));
}
}
class
Group
extends
Entity
{
public
function
setUp
()
{
$this
->
setInheritanceMap
(
array
(
"type"
=>
2
));
$this
->
setInheritanceMap
(
array
(
'type'
=>
2
));
}
}
</
code
>
We
can
then
do
the
following
given
the
previous
table
mapping
.
<
code
type
=
"php"
>
<
code
type
=
'php'
>
$user
=
new
User
();
$user
->
name
=
"Bjarte S. Karlsen"
;
$user
->
username
=
"meus"
;
$user
->
password
=
"rat"
;
$user
->
name
=
'Bjarte S. Karlsen'
;
$user
->
username
=
'meus'
;
$user
->
password
=
'rat'
;
$user
->
save
();
$group
=
new
Group
();
$group
->
name
=
"Users"
;
$group
->
username
=
"users"
;
$group
->
password
=
"password"
;
$group
->
name
=
'Users'
;
$group
->
username
=
'users'
;
$group
->
password
=
'password'
;
$group
->
save
();
$q
=
Doctrine_Query
();
$user
=
$q
->
from
(
"Entity"
)
->
where
(
"id=?"
)
->
execute
(
array
(
$user
->
id
))
->
getFirst
();
$user
=
$q
->
from
(
'Entity'
)
->
where
(
'id=?'
)
->
execute
(
array
(
$user
->
id
))
->
getFirst
();
$q
=
Doctrine_Query
();
$group
=
$q
->
from
(
"Entity"
)
->
where
(
"id=?"
)
->
execute
(
array
(
$group
->
id
))
->
getFirst
();
$group
=
$q
->
from
(
'Entity'
)
->
where
(
'id=?'
)
->
execute
(
array
(
$group
->
id
))
->
getFirst
();
</
code
>
The
user
object
is
here
an
instance
of
User
while
the
group
object
is
an
instance
of
Group
.
...
...
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