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
62438611
Commit
62438611
authored
Jan 10, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AR WIP
parent
c9b104f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
ActiveRecord.php
framework/db/ActiveRecord.php
+26
-1
ActiveRelation.php
framework/db/ActiveRelation.php
+1
-1
No files found.
framework/db/ActiveRecord.php
View file @
62438611
...
...
@@ -856,5 +856,30 @@ abstract class ActiveRecord extends Model
return
$this
->
__isset
(
$offset
);
}
/**
* @param string $name
* @param ActiveRecord $model
* @throws Exception
*/
public
function
linkWith
(
$name
,
$model
)
{
$getter
=
'get'
.
$name
;
if
(
!
method_exists
(
$this
,
$getter
))
{
throw
new
Exception
(
'Unknown relation: '
.
$name
);
}
$relation
=
$this
->
$getter
();
if
(
!
$relation
instanceof
ActiveRelation
)
{
throw
new
Exception
(
'Unknown relation: '
.
$name
);
}
if
(
$relation
->
multiple
)
{
foreach
(
$relation
->
link
as
$a
=>
$b
)
{
$key
=
$this
->
$b
;
if
(
$key
===
null
)
{
throw
new
Exception
(
'key null'
);
}
$model
->
$a
=
$this
->
$b
;
}
return
$model
->
save
(
false
);
}
}
}
framework/db/ActiveRelation.php
View file @
62438611
...
...
@@ -41,7 +41,7 @@ class ActiveRelation extends ActiveQuery
* must be the corresponding columns from the primary table.
* Do not prefix or quote the column names as they will be done automatically by Yii.
*/
p
rotected
$link
;
p
ublic
$link
;
/**
* @var array|ActiveRelation
*/
...
...
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