{
$this->_attributes[$key] = $value;
}
+
+ public function setAttributeIfNotSet($key, $value)
+ {
+ if ($this->hasAttribute($key)) {
+ return;
+ }
+ $this->setAttribute($key, $value);
+ }
}
{
return ['type' => $this->_adminType, 'column' => false, 'form' => 'both', 'rules' => '',
'fillable' => true, 'guarded' => false, 'hidden' => false, 'translatable' => $this->_translatable,
- 'column_type' => 'text', 'default' => '', 'cast' => $this->_cast];
+ 'column_type' => 'text', 'default' => '', 'cast' => $this->_cast, 'fake' => false, 'store_in' => false];
}
public function __construct($attributes)
protected function _postSetAttributes()
{
-
+ if ($this->getAttribute('fake', false) === true) {
+ $this->setAttributeIfNotSet('store_in', 'extras');
+ }
}
}
if ($field->getAttribute('translatable')) {
$this->translatable[] = $name;
}
-
if ($field->getAttribute('cast', false) !== false) {
$this->casts[$field->getAttribute('name')] = $field->getAttribute('name');
}
+
+
}
/**
}
}
+ $fakeColumns = [];
+
foreach ($this->_fields as $field) {
- if ($field->getRelationship() != 'belongsToMany') {
- $field->defineDbColumn($table);
+ if ($field->getRelationship() == 'belongsToMany') {
+ continue;
}
+ if ($field->getAttribute('store_in', false) !== false) {
+ $fakeColumns[] = $field->getAttribute('store_in');
+ continue;
+ }
+ $field->defineDbColumn($table);
+ }
+
+ $fakeColumns = array_unique($fakeColumns);
+ foreach ($fakeColumns as $fakeColumn) {
+ $table->addColumn($fakeColumn, 'text');
}
if ($this->timestamps) {
{
if (is_string($field)) {
foreach ($this->_fields as $f) {
- if($f->getAttribute('entity')==$field){
- $field=$f;
+ if ($f->getAttribute('entity') == $field) {
+ $field = $f;
break;
}
}