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
af030c5f
Commit
af030c5f
authored
Mar 20, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added $skipIfSet to ActiveRecord::loadDefaultValues
parent
4b14a8c6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
ActiveRecord.php
framework/db/ActiveRecord.php
+3
-2
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+12
-0
No files found.
framework/db/ActiveRecord.php
View file @
af030c5f
...
...
@@ -96,12 +96,13 @@ class ActiveRecord extends BaseActiveRecord
/**
* Loads default values from database table schema
*
* @param boolean $skipIfSet if existing value should be preserved
* @return static model instance
*/
public
function
loadDefaultValues
()
public
function
loadDefaultValues
(
$skipIfSet
=
true
)
{
foreach
(
$this
->
getTableSchema
()
->
columns
as
$column
)
{
if
(
$column
->
defaultValue
)
{
if
(
$column
->
defaultValue
&&
!
(
$skipIfSet
&&
$this
->
{
$column
->
name
}
!==
null
)
)
{
$this
->
{
$column
->
name
}
=
$column
->
defaultValue
;
}
}
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
af030c5f
...
...
@@ -505,5 +505,17 @@ class ActiveRecordTest extends DatabaseTestCase
}
else
{
$this
->
assertEquals
(
'2002-01-01 00:00:00'
,
$model
->
time
);
}
$model
=
new
Type
();
$model
->
char_col2
=
'not something'
;
$model
->
loadDefaultValues
();
$this
->
assertEquals
(
'not something'
,
$model
->
char_col2
);
$model
=
new
Type
();
$model
->
char_col2
=
'not something'
;
$model
->
loadDefaultValues
(
false
);
$this
->
assertEquals
(
'something'
,
$model
->
char_col2
);
}
}
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