mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 19:42:41 +00:00
Changing Model::hasField() api to accept second parameter for checking existance of virtual field
This commit is contained in:
parent
ec672e99e8
commit
0ab2078284
1 changed files with 8 additions and 1 deletions
|
@ -1009,12 +1009,13 @@ class Model extends Overloadable {
|
||||||
* Returns true if the supplied field exists in the model's database table.
|
* 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 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.
|
* @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,
|
* If $name is an array of field names, returns the first field that exists,
|
||||||
* or false if none exist.
|
* or false if none exist.
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function hasField($name) {
|
function hasField($name, $checkVirtual = false) {
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
foreach ($name as $n) {
|
foreach ($name as $n) {
|
||||||
if ($this->hasField($n)) {
|
if ($this->hasField($n)) {
|
||||||
|
@ -1024,6 +1025,12 @@ class Model extends Overloadable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($checkVirtual && !empty($this->virtualFields)) {
|
||||||
|
if (array_key_exists($name,$this->virtualFields)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($this->_schema)) {
|
if (empty($this->_schema)) {
|
||||||
$this->schema();
|
$this->schema();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue