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
e503a364
Commit
e503a364
authored
May 26, 2014
by
Paul Klimov
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3586 from klimov-paul/2020-doc-cross-dbms-relations
Fix for #2020: docs about cross-DBMS relations
parents
ac195085
29ff0cb2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
1 deletion
+47
-1
db-active-record.md
docs/guide/db-active-record.md
+47
-1
No files found.
docs/guide/db-active-record.md
View file @
e503a364
...
...
@@ -387,9 +387,9 @@ class Customer extends \yii\db\ActiveRecord
class
Order
extends
\yii\db\ActiveRecord
{
// Order has_one Customer via Customer.id -> customer_id
public
function
getCustomer
()
{
// Order has_one Customer via Customer.id -> customer_id
return
$this
->
hasOne
(
Customer
::
className
(),
[
'id'
=>
'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.
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 features 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
------
...
...
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