Skip to content

Commit

Permalink
Merge pull request #87 from atk4/implement-mandatory-property
Browse files Browse the repository at this point in the history
Implement Field->mandatory property
  • Loading branch information
romaninsh committed Aug 4, 2016
2 parents 09c76a1 + 382b6cb commit fba9c5a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Field
public $default = null;

/**
* Field type, for example, 'string', 'boolean', 'numeric' etc.
* Field type, for example, 'string', 'boolean', 'numeric', 'int', 'date' etc.
*
* @var string
*/
Expand Down Expand Up @@ -54,6 +54,13 @@ class Field
*/
public $editable = true;

/**
* Is field mandatory? By default fields are not mandatory.
*
* @var bool|string
*/
public $mandatory = false;

/**
* Setting this to true will never actually store
* the field in the database. It will action as normal,
Expand Down
7 changes: 6 additions & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ public function init()
$this->_init();

if ($this->id_field) {
$this->addField($this->id_field, ['system' => true, 'type' => 'int', 'editable' => false]);
$this->addField($this->id_field, [
'system' => true,
'type' => 'int',
'mandatory' => true,
'editable' => false,
]);
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/Relation_One.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class Relation_One
*/
public $editable = true;

/**
* Is field mandatory? By default fields are not mandatory.
*
* @var bool|string
*/
public $mandatory = false;

/**
* Default constructor. Will copy argument into properties.
*
Expand Down Expand Up @@ -113,11 +120,12 @@ public function init()
// but if we try to do so here, then we end up in infinite loop :(
//$m = $this->getModel();
$this->owner->addField($this->our_field, [
'type' => 'int', //$m->getElement($m->id_field)->type,
'system' => false,
'join' => $this->join,
'default' => $this->default,
'editable' => $this->editable,
'type' => 'int', //$m->getElement($m->id_field)->type,
'system' => false,
'join' => $this->join,
'default' => $this->default,
'editable' => $this->editable,
'mandatory' => $this->mandatory,
]);
}
}
Expand Down

0 comments on commit fba9c5a

Please sign in to comment.