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
ac9b3159
Commit
ac9b3159
authored
Jan 07, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed a via query bug.
parent
fe90d4dd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
22 deletions
+16
-22
ActiveRelation.php
framework/db/ActiveRelation.php
+16
-22
No files found.
framework/db/ActiveRelation.php
View file @
ac9b3159
...
...
@@ -49,21 +49,17 @@ class ActiveRelation extends ActiveQuery
/**
* @param string $relationName
* @param
array|\Closure $options
* @param
callback $callback
* @return ActiveRelation
*/
public
function
via
(
$relationName
,
$
options
=
null
)
public
function
via
(
$relationName
,
$
callback
=
null
)
{
/** @var $relation ActiveRelation */
$relation
=
$this
->
primaryModel
->
$relationName
();
$relation
->
primaryModel
=
null
;
$this
->
via
=
array
(
$relationName
,
$relation
);
if
(
is_array
(
$options
))
{
foreach
(
$options
as
$name
=>
$value
)
{
$this
->
$name
=
$value
;
}
}
elseif
(
$options
instanceof
\Closure
)
{
$options
(
$relation
);
if
(
$callback
!==
null
)
{
call_user_func
(
$callback
,
$relation
);
}
return
$this
;
}
...
...
@@ -71,10 +67,10 @@ class ActiveRelation extends ActiveQuery
/**
* @param string $tableName
* @param array $link
* @param
array|\Closure $options
* @param
callback $callback
* @return ActiveRelation
*/
public
function
viaTable
(
$tableName
,
$link
,
$
options
=
null
)
public
function
viaTable
(
$tableName
,
$link
,
$
callback
=
null
)
{
$relation
=
new
ActiveRelation
(
array
(
'modelClass'
=>
get_class
(
$this
->
primaryModel
),
...
...
@@ -84,12 +80,8 @@ class ActiveRelation extends ActiveQuery
'asArray'
=>
true
,
));
$this
->
via
=
$relation
;
if
(
is_array
(
$options
))
{
foreach
(
$options
as
$name
=>
$value
)
{
$this
->
$name
=
$value
;
}
}
elseif
(
$options
instanceof
\Closure
)
{
$options
(
$relation
);
if
(
$callback
!==
null
)
{
call_user_func
(
$callback
,
$relation
);
}
return
$this
;
}
...
...
@@ -110,12 +102,14 @@ class ActiveRelation extends ActiveQuery
$this
->
filterByModels
(
$viaModels
);
}
elseif
(
is_array
(
$this
->
via
))
{
// via relation
$relationName
=
$this
->
via
[
0
];
$viaModels
=
$this
->
primaryModel
->
$relationName
;
if
(
$viaModels
===
null
)
{
$viaModels
=
array
();
}
elseif
(
!
is_array
(
$viaModels
))
{
$viaModels
=
array
(
$viaModels
);
/** @var $viaQuery ActiveRelation */
list
(
$viaName
,
$viaQuery
)
=
$this
->
via
;
$viaQuery
->
primaryModel
=
$this
->
primaryModel
;
if
(
$viaQuery
->
multiple
)
{
$this
->
primaryModel
->
$viaName
=
$viaModels
=
$viaQuery
->
all
();
}
else
{
$this
->
primaryModel
->
$viaName
=
$model
=
$viaQuery
->
one
();
$viaModels
=
$model
===
null
?
array
()
:
array
(
$model
);
}
$this
->
filterByModels
(
$viaModels
);
}
else
{
...
...
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