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
d0efd96e
Commit
d0efd96e
authored
Sep 05, 2007
by
jackbravo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update syntax for relationships on models
parent
cd7f42de
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
29 deletions
+76
-29
Album.php
models/Album.php
+10
-4
Author.php
models/Author.php
+10
-2
Book.php
models/Book.php
+10
-4
Group.php
models/Group.php
+12
-6
RelationTest.php
models/RelationTest.php
+10
-4
Song.php
models/Song.php
+10
-2
User.php
models/User.php
+14
-7
No files found.
models/Album.php
View file @
d0efd96e
<?php
class
Album
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
ownsMany
(
'Song'
,
'Song.album_id'
);
class
Album
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
'Song'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'album_id'
));
$this
->
hasOne
(
'User'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'id'
,
'onDelete'
=>
'CASCADE'
));
}
public
function
setTableDefinition
()
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'user_id'
,
'integer'
);
$this
->
hasColumn
(
'name'
,
'string'
,
20
);
}
...
...
models/Author.php
View file @
d0efd96e
<?php
class
Author
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
class
Author
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasOne
(
'Book'
,
array
(
'local'
=>
'book_id'
,
'foreign'
=>
'id'
,
'onDelete'
=>
'CASCADE'
));
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'book_id'
,
'integer'
);
$this
->
hasColumn
(
'name'
,
'string'
,
20
);
}
...
...
models/Book.php
View file @
d0efd96e
<?php
class
Book
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
ownsMany
(
'Author'
,
'Author.book_id'
);
class
Book
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
'Author'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'book_id'
));
$this
->
hasOne
(
'User'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'id'
,
'onDelete'
=>
'CASCADE'
));
}
public
function
setTableDefinition
()
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'user_id'
,
'integer'
);
$this
->
hasColumn
(
'name'
,
'string'
,
20
);
}
...
...
models/Group.php
View file @
d0efd96e
<?php
// grouptable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called
require_once
(
'Entity.php'
);
// grouptable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called
class
GroupTable
{
}
class
Group
extends
Entity
{
public
function
setUp
()
{
class
Group
extends
Entity
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
hasMany
(
'User'
,
'Groupuser.user_id'
);
// $this->option('inheritanceMap', array('type' => 1));
$this
->
hasMany
(
'User'
,
array
(
'local'
=>
'group_id'
,
'foreign'
=>
'user_id'
,
'refClass'
=>
'Groupuser'
,
));
}
}
models/RelationTest.php
View file @
d0efd96e
...
...
@@ -4,7 +4,7 @@ class RelationTest extends Doctrine_Record
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'name'
,
'string'
,
200
);
$this
->
hasColumn
(
'
child
_id'
,
'integer'
);
$this
->
hasColumn
(
'
parent
_id'
,
'integer'
);
}
}
...
...
@@ -12,8 +12,14 @@ class RelationTestChild extends RelationTest
{
public
function
setUp
()
{
$this
->
hasOne
(
'RelationTest as Parent'
,
'RelationTestChild.child_id'
);
$this
->
ownsMany
(
'RelationTestChild as Children'
,
'RelationTestChild.child_id'
);
$this
->
hasOne
(
'RelationTest as Parent'
,
array
(
'local'
=>
'parent_id'
,
'foreign'
=>
'id'
,
'onDelete'
=>
'CASCADE'
,
));
$this
->
hasMany
(
'RelationTestChild as Children'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'parent_id'
,
));
}
}
models/Song.php
View file @
d0efd96e
<?php
class
Song
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
class
Song
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasOne
(
'Album'
,
array
(
'local'
=>
'album_id'
,
'foreign'
=>
'id'
,
'onDelete'
=>
'CASCADE'
));
}
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'album_id'
,
'integer'
);
$this
->
hasColumn
(
'genre'
,
'string'
,
20
);
$this
->
hasColumn
(
'title'
,
'string'
,
30
);
...
...
models/User.php
View file @
d0efd96e
...
...
@@ -2,6 +2,8 @@
require_once
(
'Entity.php'
);
// UserTable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('User') is called
class
UserTable
extends
Doctrine_Table
{
}
class
User
extends
Entity
...
...
@@ -9,13 +11,18 @@ class User extends Entity
public
function
setUp
()
{
parent
::
setUp
();
$this
->
hasMany
(
'Address'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'address_id'
,
'refClass'
=>
'EntityAddress'
));
$this
->
ownsMany
(
'Album'
,
'Album.user_id'
);
$this
->
ownsMany
(
'Book'
,
'Book.user_id'
);
$this
->
hasMany
(
'Group'
,
'Groupuser.group_id'
);
// $this->option('inheritanceMap', array('type' => 0));
$this
->
hasMany
(
'Address'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'address_id'
,
'refClass'
=>
'EntityAddress'
,
));
$this
->
hasMany
(
'Album'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'user_id'
));
$this
->
hasMany
(
'Book'
,
array
(
'local'
=>
'id'
,
'foreign'
=>
'user_id'
));
$this
->
hasMany
(
'Group'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'group_id'
,
'refClass'
=>
'Groupuser'
,
));
}
/** Custom validation */
public
function
validate
()
...
...
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