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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
ffe94018
Commit
ffe94018
authored
Feb 02, 2015
by
Angel Faryshta Guevara
Committed by
Qiang Xue
Feb 03, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify findByCondition
parent
057828c0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
10 deletions
+8
-10
ActiveRecord.php
framework/db/ActiveRecord.php
+3
-4
BaseActiveRecord.php
framework/db/BaseActiveRecord.php
+5
-6
No files found.
framework/db/ActiveRecord.php
View file @
ffe94018
...
...
@@ -165,12 +165,11 @@ class ActiveRecord extends BaseActiveRecord
* Finds ActiveRecord instance(s) by the given condition.
* This method is internally called by [[findOne()]] and [[findAll()]].
* @param mixed $condition please refer to [[findOne()]] for the explanation of this parameter
* @param boolean $one whether this method is called by [[findOne()]] or [[findAll()]]
* @return static|static[]
* @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
* @throws InvalidConfigException if there is no primary key defined
* @internal
*/
protected
static
function
findByCondition
(
$condition
,
$one
)
protected
static
function
findByCondition
(
$condition
)
{
$query
=
static
::
find
();
...
...
@@ -188,7 +187,7 @@ class ActiveRecord extends BaseActiveRecord
}
}
return
$
one
?
$query
->
andWhere
(
$condition
)
->
one
()
:
$query
->
andWhere
(
$condition
)
->
all
(
);
return
$
query
->
andWhere
(
$condition
);
}
/**
...
...
framework/db/BaseActiveRecord.php
View file @
ffe94018
...
...
@@ -98,7 +98,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
public
static
function
findOne
(
$condition
)
{
return
static
::
findByCondition
(
$condition
,
true
);
return
static
::
findByCondition
(
$condition
)
->
one
(
);
}
/**
...
...
@@ -107,19 +107,18 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
public
static
function
findAll
(
$condition
)
{
return
static
::
findByCondition
(
$condition
,
false
);
return
static
::
findByCondition
(
$condition
)
->
all
(
);
}
/**
* Finds ActiveRecord instance(s) by the given condition.
* This method is internally called by [[findOne()]] and [[findAll()]].
* @param mixed $condition please refer to [[findOne()]] for the explanation of this parameter
* @param boolean $one whether this method is called by [[findOne()]] or [[findAll()]]
* @return static|static[]
* @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
* @throws InvalidConfigException if there is no primary key defined
* @internal
*/
protected
static
function
findByCondition
(
$condition
,
$one
)
protected
static
function
findByCondition
(
$condition
)
{
$query
=
static
::
find
();
...
...
@@ -133,7 +132,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
}
}
return
$
one
?
$query
->
andWhere
(
$condition
)
->
one
()
:
$query
->
andWhere
(
$condition
)
->
all
(
);
return
$
query
->
andWhere
(
$condition
);
}
/**
...
...
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