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
d5f40b42
Commit
d5f40b42
authored
Dec 22, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ActiveRecordInterface::getOldPrimaryKey().
parent
0035a982
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
10 deletions
+22
-10
ActiveRecordInterface.php
framework/yii/db/ActiveRecordInterface.php
+18
-2
ExistValidator.php
framework/yii/validators/ExistValidator.php
+2
-2
UniqueValidator.php
framework/yii/validators/UniqueValidator.php
+2
-6
No files found.
framework/yii/db/ActiveRecordInterface.php
View file @
d5f40b42
...
@@ -70,6 +70,23 @@ interface ActiveRecordInterface
...
@@ -70,6 +70,23 @@ interface ActiveRecordInterface
public
function
getPrimaryKey
(
$asArray
=
false
);
public
function
getPrimaryKey
(
$asArray
=
false
);
/**
/**
* Returns the old primary key value(s).
* This refers to the primary key value that is populated into the record
* after executing a find method (e.g. find(), findAll()).
* The value remains unchanged even if the primary key attribute is manually assigned with a different value.
* @param boolean $asArray whether to return the primary key value as an array. If true,
* the return value will be an array with column name as key and column value as value.
* If this is false (default), a scalar value will be returned for non-composite primary key.
* @property mixed The old primary key value. An array (column name => column value) is
* returned if the primary key is composite. A string is returned otherwise (null will be
* returned if the key value is null).
* @return mixed the old primary key value. An array (column name => column value) is returned if the primary key
* is composite or `$asArray` is true. A string is returned otherwise (null will be returned if
* the key value is null).
*/
public
function
getOldPrimaryKey
(
$asArray
=
false
);
/**
* Creates an [[ActiveQueryInterface|ActiveQuery]] instance for query purpose.
* Creates an [[ActiveQueryInterface|ActiveQuery]] instance for query purpose.
*
*
* This method is usually ment to be used like this:
* This method is usually ment to be used like this:
...
@@ -290,4 +307,4 @@ interface ActiveRecordInterface
...
@@ -290,4 +307,4 @@ interface ActiveRecordInterface
* If true, the model containing the foreign key will be deleted.
* If true, the model containing the foreign key will be deleted.
*/
*/
public
function
unlink
(
$name
,
$model
,
$delete
=
false
);
public
function
unlink
(
$name
,
$model
,
$delete
=
false
);
}
}
\ No newline at end of file
framework/yii/validators/ExistValidator.php
View file @
d5f40b42
...
@@ -61,7 +61,7 @@ class ExistValidator extends Validator
...
@@ -61,7 +61,7 @@ class ExistValidator extends Validator
return
;
return
;
}
}
/** @var \yii\db\ActiveRecord $className */
/** @var \yii\db\ActiveRecord
Interface
$className */
$className
=
$this
->
className
===
null
?
get_class
(
$object
)
:
$this
->
className
;
$className
=
$this
->
className
===
null
?
get_class
(
$object
)
:
$this
->
className
;
$attributeName
=
$this
->
attributeName
===
null
?
$attribute
:
$this
->
attributeName
;
$attributeName
=
$this
->
attributeName
===
null
?
$attribute
:
$this
->
attributeName
;
$query
=
$className
::
find
();
$query
=
$className
::
find
();
...
@@ -85,7 +85,7 @@ class ExistValidator extends Validator
...
@@ -85,7 +85,7 @@ class ExistValidator extends Validator
if
(
$this
->
attributeName
===
null
)
{
if
(
$this
->
attributeName
===
null
)
{
throw
new
InvalidConfigException
(
'The "attributeName" property must be set.'
);
throw
new
InvalidConfigException
(
'The "attributeName" property must be set.'
);
}
}
/** @var \yii\db\ActiveRecord $className */
/** @var \yii\db\ActiveRecord
Interface
$className */
$className
=
$this
->
className
;
$className
=
$this
->
className
;
$query
=
$className
::
find
();
$query
=
$className
::
find
();
$query
->
where
([
$this
->
attributeName
=>
$value
]);
$query
->
where
([
$this
->
attributeName
=>
$value
]);
...
...
framework/yii/validators/UniqueValidator.php
View file @
d5f40b42
...
@@ -8,8 +8,6 @@
...
@@ -8,8 +8,6 @@
namespace
yii\validators
;
namespace
yii\validators
;
use
Yii
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\db\ActiveRecord
;
use
yii\db\ActiveRecordInterface
;
use
yii\db\ActiveRecordInterface
;
/**
/**
...
@@ -57,7 +55,7 @@ class UniqueValidator extends Validator
...
@@ -57,7 +55,7 @@ class UniqueValidator extends Validator
return
;
return
;
}
}
/** @var \yii\db\ActiveRecord $className */
/** @var \yii\db\ActiveRecord
Interface
$className */
$className
=
$this
->
className
===
null
?
get_class
(
$object
)
:
$this
->
className
;
$className
=
$this
->
className
===
null
?
get_class
(
$object
)
:
$this
->
className
;
$attributeName
=
$this
->
attributeName
===
null
?
$attribute
:
$this
->
attributeName
;
$attributeName
=
$this
->
attributeName
===
null
?
$attribute
:
$this
->
attributeName
;
...
@@ -69,9 +67,7 @@ class UniqueValidator extends Validator
...
@@ -69,9 +67,7 @@ class UniqueValidator extends Validator
$exists
=
$query
->
exists
();
$exists
=
$query
->
exists
();
}
else
{
}
else
{
// if current $object is in the database already we can't use exists()
// if current $object is in the database already we can't use exists()
$query
->
limit
(
2
);
$objects
=
$query
->
limit
(
2
)
->
all
();
$objects
=
$query
->
all
();
$n
=
count
(
$objects
);
$n
=
count
(
$objects
);
if
(
$n
===
1
)
{
if
(
$n
===
1
)
{
if
(
in_array
(
$attributeName
,
$className
::
primaryKey
()))
{
if
(
in_array
(
$attributeName
,
$className
::
primaryKey
()))
{
...
...
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