Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Фикс пустого значения по умолчанию #345

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class DataSource_Hybrid_Field_Source_Document extends DataSource_Hybrid_Field_Source_OneToOne {

protected $_is_searchable = FALSE;

protected $default = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В этой правке есть несколько проблем.

  1. Все защищенные методы и параметры в CMS начинаются со знака "_", пример: protected $_default
  2. Значение по умолчанию лучше вынести в опции поля protected $_props = array(..., 'default' => 0, ...) либо public $default = 0;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тогда думаю имеет смысл дать права системе создавать поле с пустым значением по умолчанию.
Иначе придется периодически добавлять эту опцию для поля, что лично мне, например, не столь важно. Тем более если поле обязательно для заполнения. Т.е. априори человеку нужно будет что-то указать здесь при создании нового объекта, тогда какой смысл в этом ограничении?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для каждого типа поля свой тип значения по умолчанию, в данном случае можно указать

public function default_value()
{
    return 0;
}

protected $_props = array(
'isreq' => TRUE,
'ds_type' => NULL,
Expand Down Expand Up @@ -139,4 +139,4 @@ public function get_query_props(\Database_Query $query, DataSource_Hybrid_Agent
->on('dss' . $this->id . '.published', '=', DB::expr( 1 ))
->select(array('dss'.$this->id.'.header', $this->id . 'header'));
}
}
}