Skip to content

Commit 0ab2078

Browse files
committed
Changing Model::hasField() api to accept second parameter for checking existance of virtual field
1 parent ec672e9 commit 0ab2078

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cake/libs/model/model.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,12 +1009,13 @@ function getColumnType($column) {
10091009
* Returns true if the supplied field exists in the model's database table.
10101010
*
10111011
* @param mixed $name Name of field to look for, or an array of names
1012+
* @param boolean $checkVirtual checks if the field is declared as virtual
10121013
* @return mixed If $name is a string, returns a boolean indicating whether the field exists.
10131014
* If $name is an array of field names, returns the first field that exists,
10141015
* or false if none exist.
10151016
* @access public
10161017
*/
1017-
function hasField($name) {
1018+
function hasField($name, $checkVirtual = false) {
10181019
if (is_array($name)) {
10191020
foreach ($name as $n) {
10201021
if ($this->hasField($n)) {
@@ -1024,6 +1025,12 @@ function hasField($name) {
10241025
return false;
10251026
}
10261027

1028+
if ($checkVirtual && !empty($this->virtualFields)) {
1029+
if (array_key_exists($name,$this->virtualFields)) {
1030+
return true;
1031+
}
1032+
}
1033+
10271034
if (empty($this->_schema)) {
10281035
$this->schema();
10291036
}

0 commit comments

Comments
 (0)