Skip to content

Commit 0996187

Browse files
committed
add addMethod for many members
in models generation
1 parent f6c55ef commit 0996187

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Ubiquity/orm/creator/Member.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* This class is part of Ubiquity
1818
*
1919
* @author jcheron <[email protected]>
20-
* @version 1.0.2
20+
* @version 1.0.3
2121
* @category ubiquity.dev
2222
*
2323
*/
@@ -192,10 +192,29 @@ public function getSetter() {
192192
return $result;
193193
}
194194

195+
public function getAddInManyMember() {
196+
if (\substr($this->name, - 1) === 's') {
197+
$name = \substr($this->name, 0, - 1);
198+
}
199+
$result = "\n\t public function add" . \ucfirst($name) . '($' . $name . "){\n";
200+
$result .= "\t\t" . '$this->' . $this->name . '[]=$' . $name . ";\n";
201+
$result .= "\t}\n";
202+
return $result;
203+
}
204+
195205
public function hasAnnotations() {
196206
return \count($this->annotations) > 1;
197207
}
198208

209+
public function isMany() {
210+
foreach ($this->annotations as $annot) {
211+
if (($annot instanceof OneToManyAnnotation) || ($annot instanceof ManyToManyAnnotation)) {
212+
return true;
213+
}
214+
}
215+
return false;
216+
}
217+
199218
public function isNullable() {
200219
if (isset($this->annotations['column']))
201220
return $this->annotations['column']->nullable;

src/Ubiquity/orm/creator/Model.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* This class is part of Ubiquity
1010
*
1111
* @author jcheron <[email protected]>
12-
* @version 1.0.4
12+
* @version 1.0.5
1313
* @category ubiquity.dev
1414
*
1515
*/
@@ -126,6 +126,9 @@ public function __toString() {
126126
foreach ($members as $member) {
127127
$result .= $member->getGetter();
128128
$result .= $member->getSetter();
129+
if ($member->isMany()) {
130+
$result .= $member->getAddInManyMember();
131+
}
129132
}
130133
$result .= $this->getToString();
131134
$result .= "\n}";

0 commit comments

Comments
 (0)