Skip to content

Commit

Permalink
Changing Model::hasField() api to accept second parameter for checkin…
Browse files Browse the repository at this point in the history
…g existance of virtual field
  • Loading branch information
lorenzo committed Dec 11, 2009
1 parent ec672e9 commit 0ab2078
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cake/libs/model/model.php
Expand Up @@ -1009,12 +1009,13 @@ function getColumnType($column) {
* Returns true if the supplied field exists in the model's database table.
*
* @param mixed $name Name of field to look for, or an array of names
* @param boolean $checkVirtual checks if the field is declared as virtual
* @return mixed If $name is a string, returns a boolean indicating whether the field exists.
* If $name is an array of field names, returns the first field that exists,
* or false if none exist.
* @access public
*/
function hasField($name) {
function hasField($name, $checkVirtual = false) {
if (is_array($name)) {
foreach ($name as $n) {
if ($this->hasField($n)) {
Expand All @@ -1024,6 +1025,12 @@ function hasField($name) {
return false;
}

if ($checkVirtual && !empty($this->virtualFields)) {
if (array_key_exists($name,$this->virtualFields)) {
return true;
}
}

if (empty($this->_schema)) {
$this->schema();
}
Expand Down

0 comments on commit 0ab2078

Please sign in to comment.