public function __getInternalOrm($name) { if ($name == 'pk') { $name = $this->primaryKey(); $name = array_shift($name); } $meta = static::getMeta(); if ($meta->hasFileField($name)) { $fileField = $this->getField($name); $fileField->setModel($this); $fileField->setDbValue($this->getAttribute($name)); return $fileField; } if ($meta->hasOneToOneField($name)) { /* @var $field \Mindy\Orm\Fields\OneToOneField */ $field = $meta->getField($name); $field->setModel($this); return $field->getValue(); } if ($meta->hasForeignField($name) && $this->hasAttribute($name) === false) { $value = $this->getAttribute($name . '_id'); if (is_null($value)) { return $value; } else { /* @var $field \Mindy\Orm\Fields\ForeignField */ $field = $meta->getForeignField($name)->setModel($this)->setValue($value); return $field->getValue(); } } if ($meta->hasManyToManyField($name) || $meta->hasHasManyField($name)) { /* @var $field \Mindy\Orm\Fields\ManyToManyField|\Mindy\Orm\Fields\HasManyField */ $field = $meta->getField($name); $field->setModel($this); return $field->getManager(); } if ($meta->hasField($name) && is_a($this->getField($name), JsonField::className())) { $field = $this->getField($name); $field->setModel($this); $field->setDbValue($this->getAttribute($name)); return $field->getValue(); } if (isset($this->_attributes[$name]) || array_key_exists($name, $this->_attributes)) { return $this->_attributes[$name]; } elseif ($this->hasAttribute($name)) { return $this->hasField($name) ? $this->getField($name)->default : null; } if (!in_array($name, $this->attributes()) && $this->hasField($name)) { throw new \Mindy\Query\Exception(Translate::getInstance()->t("orm", "'{name}' column is missing in database. Please check database structure", ['{name}' => $name])); } return $this->__getInternal($name); }
public function testValidation() { $field = new JsonField(); $field->setValue(new Test()); $this->assertFalse($field->isValid()); }