File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 22
33namespace PHPFUI \ORM ;
44
5+ /**
6+ * get a related record
7+ */
58class RelatedRecord extends \PHPFUI \ORM \VirtualField
69 {
710 /**
8- * @param array<string> $parameters
11+ * @param array<string> $parameters recordClassName fieldName
912 */
1013 public function getValue (array $ parameters ) : mixed
1114 {
1215 $ class = \array_shift ($ parameters );
16+ $ field = \array_shift ($ parameters );
17+
18+ if ($ field )
19+ {
20+ return new $ class ($ this ->currentRecord ->$ field );
21+ }
1322
1423 return new $ class ($ this ->currentRecord [$ this ->fieldName . \PHPFUI \ORM ::$ idSuffix ]);
1524 }
@@ -20,18 +29,25 @@ public function getValue(array $parameters) : mixed
2029 public function setValue (mixed $ value , array $ parameters ) : void
2130 {
2231 $ class = \array_shift ($ parameters );
32+ $ field = \array_shift ($ parameters );
2333
2434 if (! ($ value instanceof $ class ))
2535 {
2636 throw new \PHPFUI \ORM \Exception (__METHOD__ . ': Error - ' . \get_debug_type ($ value ) . ' is not an instance of ' . $ class );
2737 }
38+
2839 $ primaryKeyValues = $ value ->getPrimaryKeyValues ();
2940
3041 if (1 != \count ($ primaryKeyValues ))
3142 {
3243 throw new \PHPFUI \ORM \Exception (__METHOD__ . ': Error - ' . \get_debug_type ($ value ) . ' does not have a single primary key ' );
3344 }
3445
35- $ this ->currentRecord [$ this ->fieldName . \PHPFUI \ORM ::$ idSuffix ] = \array_shift ($ primaryKeyValues );
46+ if (! $ field )
47+ {
48+ $ field = $ this ->fieldName . \PHPFUI \ORM ::$ idSuffix ;
49+ }
50+
51+ $ this ->currentRecord [$ field ] = \array_shift ($ primaryKeyValues );
3652 }
3753 }
You can’t perform that action at this time.
0 commit comments