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
43f19e8a
Commit
43f19e8a
authored
Dec 12, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use andWhere() in AR::find() to work properly with default scope
fixes #1469
parent
3fba6dc3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
4 deletions
+33
-4
ActiveRecord.php
extensions/yii/elasticsearch/ActiveRecord.php
+2
-2
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+14
-0
ActiveRecordInterface.php
framework/yii/db/ActiveRecordInterface.php
+14
-0
BaseActiveRecord.php
framework/yii/db/BaseActiveRecord.php
+2
-2
No files found.
extensions/yii/elasticsearch/ActiveRecord.php
View file @
43f19e8a
...
...
@@ -67,7 +67,7 @@ class ActiveRecord extends BaseActiveRecord
{
$query
=
static
::
createQuery
();
if
(
is_array
(
$q
))
{
if
(
count
(
$q
)
==
1
&&
(
array_key_exists
(
ActiveRecord
::
PRIMARY_KEY_NAME
,
$q
)))
{
if
(
count
(
$q
)
==
1
&&
(
array_key_exists
(
ActiveRecord
::
PRIMARY_KEY_NAME
,
$q
))
&&
$query
->
where
===
null
)
{
$pk
=
$q
[
ActiveRecord
::
PRIMARY_KEY_NAME
];
if
(
is_array
(
$pk
))
{
return
static
::
mget
(
$pk
);
...
...
@@ -75,7 +75,7 @@ class ActiveRecord extends BaseActiveRecord
return
static
::
get
(
$pk
);
}
}
return
$query
->
w
here
(
$q
)
->
one
();
return
$query
->
andW
here
(
$q
)
->
one
();
}
elseif
(
$q
!==
null
)
{
return
static
::
get
(
$q
);
}
...
...
framework/CHANGELOG.md
View file @
43f19e8a
...
...
@@ -8,6 +8,7 @@ Yii Framework 2 Change Log
-
Enh #1293: Replaced Console::showProgress() with a better approach. See Console::startProgress() for details (cebe)
-
Enh #1406: DB Schema support for Oracle Database (p0larbeer, qiangxue)
-
Enh #1437: Added ListView::viewParams (qiangxue)
-
Enh #1469: ActiveRecord::find() now works with default conditions (default scope) applied by createQuery (cebe)
-
New extension #1438:
[
MongoDB integration
](
https://github.com/yiisoft/yii2-mongodb
)
ActiveRecord and Query (klimov-paul)
2.
0.0 alpha, December 1, 2013
...
...
framework/yii/db/ActiveRecord.php
View file @
43f19e8a
...
...
@@ -150,9 +150,23 @@ class ActiveRecord extends BaseActiveRecord
/**
* Creates an [[ActiveQuery]] instance.
*
* This method is called by [[find()]], [[findBySql()]] to start a SELECT query.
* You may override this method to return a customized query (e.g. `CustomerQuery` specified
* written for querying `Customer` purpose.)
*
* You may also define default conditions that should apply to all queries unless overridden:
*
* ```php
* public static function createQuery()
* {
* return parent::createQuery()->where(['deleted' => false]);
* }
* ```
*
* Note that all queries should use [[Query::andWhere()]] and [[Query::orWhere()]] to keep the
* default condition. Using [[Query::where()]] will override the default condition.
*
* @return ActiveQuery the newly created [[ActiveQuery]] instance.
*/
public
static
function
createQuery
()
...
...
framework/yii/db/ActiveRecordInterface.php
View file @
43f19e8a
...
...
@@ -94,9 +94,23 @@ interface ActiveRecordInterface
/**
* Creates an [[ActiveQueryInterface|ActiveQuery]] instance.
*
* This method is called by [[find()]] to start a SELECT query.
* You may override this method to return a customized query (e.g. `CustomerQuery` specified
* written for querying `Customer` purpose.)
*
* You may also define default conditions that should apply to all queries unless overridden:
*
* ```php
* public static function createQuery()
* {
* return parent::createQuery()->where(['deleted' => false]);
* }
* ```
*
* Note that all queries should use [[Query::andWhere()]] and [[Query::orWhere()]] to keep the
* default condition. Using [[Query::where()]] will override the default condition.
*
* @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
*/
public
static
function
createQuery
();
...
...
framework/yii/db/BaseActiveRecord.php
View file @
43f19e8a
...
...
@@ -114,12 +114,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
{
$query
=
static
::
createQuery
();
if
(
is_array
(
$q
))
{
return
$query
->
w
here
(
$q
)
->
one
();
return
$query
->
andW
here
(
$q
)
->
one
();
}
elseif
(
$q
!==
null
)
{
// query by primary key
$primaryKey
=
static
::
primaryKey
();
if
(
isset
(
$primaryKey
[
0
]))
{
return
$query
->
w
here
([
$primaryKey
[
0
]
=>
$q
])
->
one
();
return
$query
->
andW
here
([
$primaryKey
[
0
]
=>
$q
])
->
one
();
}
else
{
throw
new
InvalidConfigException
(
get_called_class
()
.
' must have a primary key.'
);
}
...
...
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