88
99abstract class Entities
1010{
11- /**
12- * Returns a map of properties to columns for the current table
13- * @return array<string, mixed>
14- */
15- abstract protected function getMap (): array ;
16-
1711 protected PeachySql $ db ;
1812 public string $ idField = 'id ' ;
19- protected bool $ writableId = false ;
2013 private string $ idColumn ;
2114 /** @var array<string, Prop> */
2215 private array $ fullPropMap ;
@@ -37,25 +30,13 @@ public function __construct(PeachySql $db)
3730 $ propMap = Helpers::propListToPropMap ([...array_values ($ bcProps ), ...$ selectProps ]);
3831
3932 if (!isset ($ propMap [$ this ->idField ])) {
40- throw new \Exception ('Missing required id property in map ' );
41- }
42-
43- $ map = $ this ->getMap ();
44-
45- if (isset ($ map [$ this ->idField ])) {
46- /** @psalm-suppress MixedAssignment */
47- $ this ->idColumn = $ map [$ this ->idField ];
48-
49- if (!$ this ->writableId ) {
50- unset($ map [$ this ->idField ]); // prevent modifying identity column
51- }
52- } else {
53- $ idParts = explode ('. ' , $ propMap [$ this ->idField ]->col );
54- $ this ->idColumn = array_pop ($ idParts );
33+ throw new \Exception ("Missing required {$ this ->idField } property in select map " );
5534 }
5635
36+ $ idParts = explode ('. ' , $ propMap [$ this ->idField ]->col );
37+ $ this ->idColumn = array_pop ($ idParts );
5738 $ this ->fullPropMap = $ propMap ;
58- $ this ->map = $ map ;
39+ $ this ->map = $ this -> getMap () ;
5940 }
6041
6142 /**
@@ -66,6 +47,15 @@ protected function getTableName(): string
6647 return (new \ReflectionClass ($ this ))->getShortName ();
6748 }
6849
50+ /**
51+ * Returns a map of properties to writable columns for the current table.
52+ * @return array<string, mixed>
53+ */
54+ protected function getMap (): array
55+ {
56+ return [];
57+ }
58+
6959 /**
7060 * Returns the identity increment value of the table
7161 */
@@ -99,12 +89,12 @@ protected function getDefaultSort(): array
9989 }
10090
10191 /**
102- * Can be used to return a separate property map for filtering/sorting (but not inserting/updating)
92+ * Returns a map of properties to columns for selecting/ filtering/sorting.
10393 * @return array<string, mixed>
10494 */
10595 protected function getSelectMap (): array
10696 {
107- return $ this -> getMap () ;
97+ return [] ;
10898 }
10999
110100 /**
0 commit comments