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
d8b94d64
Commit
d8b94d64
authored
Nov 03, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made AR attribute manipulation behave consistent to hasAttribute()
parent
be682687
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+16
-16
No files found.
framework/yii/db/ActiveRecord.php
View file @
d8b94d64
...
...
@@ -103,7 +103,7 @@ class ActiveRecord extends Model
/**
* @var array related models indexed by the relation names
*/
private
$_related
;
private
$_related
=
[]
;
/**
...
...
@@ -376,11 +376,11 @@ class ActiveRecord extends Model
{
if
(
isset
(
$this
->
_attributes
[
$name
])
||
array_key_exists
(
$name
,
$this
->
_attributes
))
{
return
$this
->
_attributes
[
$name
];
}
elseif
(
isset
(
$this
->
getTableSchema
()
->
columns
[
$name
]
))
{
}
elseif
(
$this
->
hasAttribute
(
$name
))
{
return
null
;
}
else
{
$t
=
strtolower
(
$name
);
if
(
isset
(
$this
->
_related
[
$t
])
||
$this
->
_related
!==
null
&&
array_key_exists
(
$t
,
$this
->
_related
))
{
if
(
isset
(
$this
->
_related
[
$t
])
||
array_key_exists
(
$t
,
$this
->
_related
))
{
return
$this
->
_related
[
$t
];
}
$value
=
parent
::
__get
(
$name
);
...
...
@@ -430,7 +430,7 @@ class ActiveRecord extends Model
*/
public
function
__unset
(
$name
)
{
if
(
isset
(
$this
->
getTableSchema
()
->
columns
[
$name
]
))
{
if
(
$this
->
hasAttribute
(
$name
))
{
unset
(
$this
->
_attributes
[
$name
]);
}
else
{
$t
=
strtolower
(
$name
);
...
...
@@ -542,6 +542,16 @@ class ActiveRecord extends Model
}
/**
* Returns a value indicating whether the model has an attribute with the specified name.
* @param string $name the name of the attribute
* @return boolean whether the model has an attribute with the specified name.
*/
public
function
hasAttribute
(
$name
)
{
return
isset
(
$this
->
_attributes
[
$name
])
||
isset
(
$this
->
getTableSchema
()
->
columns
[
$name
]);
}
/**
* Returns the named attribute value.
* If this record is the result of a query and the attribute is not loaded,
* null will be returned.
...
...
@@ -571,16 +581,6 @@ class ActiveRecord extends Model
}
/**
* Returns a value indicating whether the model has an attribute with the specified name.
* @param string $name the name of the attribute
* @return boolean whether the model has an attribute with the specified name.
*/
public
function
hasAttribute
(
$name
)
{
return
isset
(
$this
->
_attributes
[
$name
])
||
isset
(
$this
->
getTableSchema
()
->
columns
[
$name
]);
}
/**
* Returns the old attribute values.
* @return array the old attribute values (name-value pairs)
*/
...
...
@@ -622,7 +622,7 @@ class ActiveRecord extends Model
*/
public
function
setOldAttribute
(
$name
,
$value
)
{
if
(
isset
(
$this
->
_oldAttributes
[
$name
])
||
isset
(
$this
->
getTableSchema
()
->
columns
[
$name
]
))
{
if
(
isset
(
$this
->
_oldAttributes
[
$name
])
||
$this
->
hasAttribute
(
$name
))
{
$this
->
_oldAttributes
[
$name
]
=
$value
;
}
else
{
throw
new
InvalidParamException
(
get_class
(
$this
)
.
' has no attribute named "'
.
$name
.
'".'
);
...
...
@@ -1138,7 +1138,7 @@ class ActiveRecord extends Model
$this
->
_attributes
[
$name
]
=
$record
->
_attributes
[
$name
];
}
$this
->
_oldAttributes
=
$this
->
_attributes
;
$this
->
_related
=
null
;
$this
->
_related
=
[]
;
return
true
;
}
...
...
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