Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
PSDI Army
yii2
Commits
b5ae6146
Commit
b5ae6146
authored
May 26, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs about cross-DBMS relations added
parent
a55d9ba8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
db-active-record.md
docs/guide/db-active-record.md
+46
-0
No files found.
docs/guide/db-active-record.md
View file @
b5ae6146
...
@@ -803,6 +803,52 @@ The [[yii\db\ActiveRecord::link()|link()]] call above will set the `customer_id`
...
@@ -803,6 +803,52 @@ The [[yii\db\ActiveRecord::link()|link()]] call above will set the `customer_id`
value of
`$customer`
and then call
[
[yii\db\ActiveRecord::save()|save()
]
] to save the order into database.
value of
`$customer`
and then call
[
[yii\db\ActiveRecord::save()|save()
]
] to save the order into database.
Cross-DBMS Relations
--------------------
ActiveRecord allows to establish relationship between entities from different DBMS. For example: between relational
database table and MongoDB collection. Such relation does not require any special code:
```
php
// Relational database Active Record
class
Customer
extends
\yii\db\ActiveRecord
{
public
static
function
tableName
()
{
return
'customer'
;
}
public
function
getComments
()
{
// Customer, stored in relational database, has many Comments, stored in MongoDB collection:
return
$this
->
hasMany
(
Comment
::
className
(),
[
'customer_id'
=>
'id'
]);
}
}
// MongoDb Active Record
class
Comment
extends
\yii\mongodb\ActiveRecord
{
public
static
function
collectionName
()
{
return
'comment'
;
}
public
function
getCustomer
()
{
// Comment, stored in MongoDB collection, has one Customer, stored in relational database:
return
$this
->
hasOne
(
Customer
::
className
(),
[
'id'
=>
'customer_id'
]);
}
}
```
All Active Record feature like: eager and lazy loading, establishing and breaking a relationship and so on, are
available for cross-DBMS relations.
Note: do not forget Active Record solutions for different DBMS may have specific methods and features, which may not be
applied for cross-DBMS relations. For example: usage of
[
[yii\db\ActiveQuery::joinWith()
]
] will obviously not work with
relation to the MongoDB collection.
Scopes
Scopes
------
------
...
...
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