Skip to content

Commit a7644b8

Browse files
committed
add autoinc fields nullable
1 parent f249055 commit a7644b8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Ubiquity/orm/creator/Member.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use Ubiquity\contents\validation\ValidationModelGenerator;
55
use Ubiquity\annotations\AnnotationsEngineInterface;
6+
use Ubiquity\db\utils\DbTypes;
67

78
/**
89
* Represents a data member in a model class.
@@ -155,6 +156,10 @@ public function getManyToOne() {
155156
public function isPrimary() {
156157
return $this->primary;
157158
}
159+
160+
public function isAutoinc(){
161+
return $this->primary && DbTypes::isInt ( $this->getDbType() );
162+
}
158163

159164
public function getGetter() {
160165
$result = "\n\tpublic function get" . \ucfirst($this->name) . "(){\n";

src/Ubiquity/orm/parser/ModelParser.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Ubiquity\utils\base\UArray;
55
use Ubiquity\contents\transformation\TransformersManager;
66
use Ubiquity\exceptions\TransformerException;
7+
use Ubiquity\db\utils\DbTypes;
78

89
/**
910
* Parse model annotation for cache generation.
@@ -105,15 +106,24 @@ public function parse($modelClass) {
105106
$this->fieldNames[$propName] = $fieldName;
106107
$this->memberNames[$fieldName] = $propName;
107108
$nullable = Reflexion::isNullable($modelClass, $propName);
109+
108110
$serializable = Reflexion::isSerializable($modelClass, $propName);
109-
if ($nullable)
110-
$this->nullableMembers[] = $propName;
111-
if (! $serializable)
111+
112+
if (! $serializable){
112113
$this->notSerializableMembers[] = $propName;
114+
}
113115
$type = Reflexion::getDbType($modelClass, $propName);
114116
if ($type === false) {
115117
$type = 'mixed';
116118
}
119+
120+
if(\array_search($fieldName, $primaryKeys)!==false && DbTypes::isInt($type)){
121+
$nullable=true;
122+
}
123+
124+
if ($nullable){
125+
$this->nullableMembers[] = $propName;
126+
}
117127
$this->fieldTypes[$propName] = $type;
118128
$accesseur = 'set' . \ucfirst($propName);
119129
if (! isset($this->accessors[$fieldName]) && \method_exists($modelClass, $accesseur)) {

0 commit comments

Comments
 (0)