-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerfORM.php
1204 lines (1025 loc) · 32.1 KB
/
PerfORM.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* PerfORM - Object-relational mapping based on David Grudl's dibi
*
* @copyright Copyright (c) 2010 Eduard 'edke' Kracmar
* @license no license set at this point
* @link http://perform.local :-)
* @category PerfORM
* @package PerfORM
*/
/**
* PerfORM
*
* Base model's class responsible for model definition and interaction
*
* @abstract
* @copyright Copyright (c) 2010 Eduard 'edke' Kracmar
* @package PerfORM
*/
abstract class PerfORM extends Object {
const AutoField = 3;
const BooleanField = 5;
const CharField = 2;
const DateField = 10;
const DateTimeField = 9;
const DecimalField = 8;
const EmailField = 13;
const ForeignKeyField = 4;
const IntegerField = 1;
const IPAddessField = 12;
const SmallIntegerField = 7;
const SlugField = 15;
const TextField = 6;
const TimeField = 11;
const URLField = 14;
/**
* Table alias
* @var string
*/
protected $alias;
/**
* Default primary key field name used when autocreating
* @var string
*/
protected $defaultPrimaryKey = 'id';
/**
* Storage for validation of model errors
* @var array
*/
protected $errors = array();
/**
* Instance of
* @var PerfORM
*/
protected $extends;
/**
* Storage for model fields
* @var array
*/
protected $fields = array();
/**
* Determines if model was frozen
* @var boolean
*/
protected $freeze = false;
/**
* Hash of model for structure checking
* @var string
*/
protected $hash;
/**
* Array of model's indexes
* @var array
*/
protected $indexes = array();
/**
* Switch for notifying if model (and which fields) was/were modified
* @var boolean
*/
protected $modified = false;
/**
* Prefix for table
* @var string
*/
protected $prefix = null;
/**
* Name of primary key field
* @var string
*/
protected $primaryKey = null;
/**
* Sql name of model and table
* @var string
*/
protected $tableName = null;
/**
* Determines if model is view or table, table is default
* @var boolean
*/
protected $view = false;
/**
* Constructor
*
* Define model (build or load from cache) and import values if set
*
* @param array $importValues
*/
public function __construct($importValues = null) {
//$backtrace= debug_backtrace();
//Debug::barDump($backtrace);
//Debug::barDump(($backtrace[0]['file']));
//Debug::barDump(($backtrace[0]['line']));
$this->buildDefinition();
/* if ( PerfORMController::useModelCaching() )
{
$this->loadDefinition();
}
else
{
$this->buildDefinition();
} */
if (!is_null($importValues)) {
$this->import($importValues);
}
}
/**
* Adds error message while validating model
* @param string $msg
*/
public function _addError($msg) {
$this->errors[] = str_replace('%s', get_class($this), $msg);
}
/**
* Adds new AutoField to model
* @param string $name
* @return AutoField
*/
protected function addAutoField($name) {
return $this->attachField(new AutoField($this, $name));
}
/**
* Adds new BooleanField to model
* @param string $name
* @return BooleanField
*/
protected function addBooleanField($name) {
return $this->attachField(new BooleanField($this, $name));
}
/**
* Adds new CharField to model
* @param string $name
* @param integer $maxLength
* @return CharField
*/
protected function addCharField($name, $maxLength) {
return $this->attachField(new CharField($this, $name, $maxLength));
}
/**
* Adds new DateField to model
* @param string $name
* @return DateField
*/
protected function addDateField($name) {
return $this->attachField(new DateField($this, $name));
}
/**
* Adds new DateTimeField to model
* @param string $name
* @return DateTimeField
*/
protected function addDateTimeField($name) {
return $this->attachField(new DateTimeField($this, $name));
}
/**
* Adds new DecimalField to model
* @param string $name
* @param integer $maxDigits
* @param integer $decimalPlaces
* @return DecimalField
*/
protected function addDecimalField($name, $maxDigits, $decimalPlaces) {
return $this->attachField(new DecimalField($this, $name, $maxDigits, $decimalPlaces));
}
/**
* Adds new EmailField to model
* @param string $name
* @param integer $maxLength
* @return EmailField
*/
protected function addEmailField($name, $maxLength) {
return $this->attachField(new EmailField($this, $name, $maxLength));
}
/**
* Adds new ForeignKeyField to model
* @param string $name
* @param PerfORM $reference
* @return ForeignKeyField
*/
protected function addForeignKeyField($name, $reference) {
$field = $this->attachField(new ForeignKeyField($this, $name, $reference));
//$this->depends[]= $reference;
return $field;
}
/**
* Adds new IPAddressField to model
* @param string $name
* @return IPAddressField
*/
protected function addIPAddressField($name) {
return $this->attachField(new IPAddressField($this, $name));
}
/**
* Adds new IntegerField to model
* @param string $name
* @return IntegerField
*/
protected function addIntegerField($name) {
return $this->attachField(new IntegerField($this, $name));
}
/**
* Adds new SlugField to model
* @param string $name
* @param integer $maxLength
* @param string $autoSource
* @return SlugField
*/
protected function addSlugField($name, $maxLength, $autoSource) {
return $this->attachField(new SlugField($this, $name, $maxLength, $autoSource));
}
/**
* Adds new SmallIntegerField to model
* @param string $name
* @return SmallIntegerField
*/
protected function addSmallIntegerField($name) {
return $this->attachField(new SmallIntegerField($this, $name));
}
/**
* Adds new TextField to model
* @param string $name
* @return TextField
*/
protected function addTextField($name) {
return $this->attachField(new TextField($this, $name));
}
/**
* Adds new TimeField to model
* @param string $name
* @return TimeField
*/
protected function addTimeField($name) {
return $this->attachField(new TimeField($this, $name));
}
/**
* Adds new URLField to model
* @param string $name
* @param integer $maxLength
* @return URLField
*/
protected function addURLField($name, $maxLength) {
return $this->attachField(new URLField($this, $name, $maxLength));
}
/**
* Adds field to model
* @param string $fieldName
* @param Field $field
*/
protected function attachField($field, $toBeginning= false) {
if ($this->isFrozen()) {
throw new Exception("Unable to attach field '" . $field->getName() . "' to frozen model.");
}
if (key_exists($field->getName(), $this->fields)) {
throw new Exception("Field with name '" . $field->getName() . "' already exists in model '" . get_class($this) . "'");
}
if ($toBeginning) {
$this->fields = array($field->getName() => $field) + $this->fields;
}
else {
$this->fields[$field->getName()] = $field;
}
//$this->fields[$field->getName()]->setModel($this);
return $this->fields[$field->getName()];
}
/**
* Adds index to model
* @param mixed $fieldNames
* @param string $indexName
* @param boolean $unique
*/
protected function addIndex($fieldNames, $indexName, $unique) {
$suffix = ($unique) ? '_key' : '_idx';
if (!is_array($fieldNames)) {
$fieldNames = array($fieldNames);
}
$key = is_null($indexName) ? implode('_', $fieldNames) . $suffix : $indexName . $suffix;
foreach ($fieldNames as $fieldName) {
if (!$this->hasField($fieldName)) {
$this->_addError(sprintf("%%s::%s (Index) field '%s' does not exists in model", $key, $fieldName));
}
if (key_exists($key, $this->indexes)) {
$this->indexes[$key]->addField($this->getField($fieldName)->getRealName());
}
else {
$this->indexes[$key] = new Index($this, $this->getField($fieldName)->getRealName(), $key, $unique);
}
}
}
/**
* Builds recursively aliases for $model
* @param PerfORM $model
*/
protected function buildAliases($model = null, & $aliases = array()) {
if (is_null($model)) {
$this->setAlias($this->getTableName());
$model = $this;
}
foreach ($model->getFields() as $field) {
if ($field->getIdent() == PerfORM::ForeignKeyField && !$field->isEnabledLazyLoading()) {
$alias = $field->getReference()->getTableName();
if (key_exists($alias, $aliases)) {
$aliases[$alias]++;
$aliasIndex = $aliases[$alias];
}
else {
$aliases[$alias] = 1;
$aliasIndex = '';
}
$field->getReference()->setAlias($alias . $aliasIndex);
foreach ($field->getReference()->getFields() as $_field) {
$_field->getModel()->setAlias($alias . $aliasIndex);
}
$this->buildAliases($field->getReference(), $aliases);
}
}
}
/**
* Build model definition from setup
*
* Model will be cached if caching is enabled (PerfORMController::useModelCaching())
*/
protected function buildDefinition() {
$this->setup();
if (!$this->getPrimaryKey() && $this->isTable() && $this->isExtended()) {
$field = new IntegerField($this, $this->defaultPrimaryKey);
$field->setPrimaryKey();
$this->attachField($field, true);
$this->setPrimaryKey($this->defaultPrimaryKey);
}
elseif (!$this->getPrimaryKey() && $this->isTable()) {
$field = new AutoField($this, $this->defaultPrimaryKey);
$field->setPrimaryKey();
$this->attachField($field, true);
$this->setPrimaryKey($this->defaultPrimaryKey);
}
$this->validate();
# indexes
foreach ($this->getFields() as $field) {
foreach ($field->getIndexes() as $index) {
$this->addIndex($field->getName(), $index->name, $index->unique);
}
}
# aliases for model
$this->buildAliases();
# model hashing
$model_hashes = array();
if ($this->isTable()) {
foreach ($this->getFields() as $field) {
$model_hashes[] = md5($field->getName() . '|' . $field->getHash());
}
foreach ($this->getIndexes() as $index) {
$model_hashes[] = md5($index->getName() . '|' . $index->getHash());
}
sort($model_hashes);
$this->hash = md5(implode('|', $model_hashes));
}
elseif ($this->isView()) {
$view = $this->getViewSetup();
$view = trim(preg_replace('#\s{2,}#m', ' ', $view));
$this->hash = md5($view);
}
/* if (PerfORMController::useModelCaching()) {
$cache = PerfORMController::getCache();
$cache->save($this->getCacheKey(), $this, array(
Cache::FILES => array(__FILE__),
));
} */
}
/**
* Checks if $model depends on this model
* @param PerfORM $model
* @return boolean
*/
public function dependsOn($model) {
foreach ($this->depends as $dependent) {
if ($model == $dependent) {
return true;
}
}
return false;
}
/**
* Fill model with values from result
* @param PerfORM $model
* @param array $values
* @result PerfORM
*/
public function fill($values) {
if ($values === false)
return;
foreach ($this->getFields() as $field) {
$key = $this->getAlias() . '__' . $field->getRealName();
if ($field->getIdent() == PerfORM::ForeignKeyField &&
!key_exists($field->getReference()->getAlias() . '__' . $field->getReference()->getPrimaryKey(), $values)) {
$field->setLazyLoadingKeyValue($values[$key]);
$field->enableLazyLoading();
}
elseif ($field->getIdent() == PerfORM::ForeignKeyField &&
!$field->isEnabledLazyLoading()
) {
$child = clone $field->getReference();
$child->fill($values);
$field->setValue($child);
}
elseif ($field->getIdent() == PerfORM::ForeignKeyField &&
$field->isEnabledLazyLoading()
) {
$field->setLazyLoadingKeyValue($values[$key]);
}
elseif (key_exists($key, $values)) {
$this->__set($field->getName(), $values[$key]);
}
else {
Debug::barDump($this);
throw new Exception("The is no value in result for field '$key'");
}
}
$this->setUnmodified();
if ($this->isExtended()) {
$this->extends->fill($values);
}
}
/**
* Freezes model's definition after building
*/
protected function freeze() {
$this->freeze = true;
foreach ($this->getFields() as $field) {
$field->freeze();
}
}
/**
* Sets inheritance
* @param PerfORM $model
*/
protected function setInheritance($model) {
$this->extends = $model;
}
/**
* Getter for alias
* @return string
*/
public function getAlias() {
return $this->alias;
}
/**
* Getter for model's cache key
* @return string
*/
protected function getCacheKey() {
return md5($this->getLastModification() . '|' . get_class($this));
}
/**
* Getter for PerfORMController's connection
* @return DibiConnection
*/
public function getConnection() {
return PerfORMController::getConnection();
}
/**
* Getter for all dependents of model
* @return array
*/
public function getDependents() {
$depends = array();
foreach ($this->getFields() as $field) {
if ($field->getIdent() == PerfORM::ForeignKeyField) {
$depends[] = $field;
}
}
return $depends;
}
/**
* Getter for parent model
* @return PerfORM
*/
public function getExtend() {
return $this->extends;
}
/**
* Getter for field with name $name
* @return Field
*/
public function getField($name, $includeExtends = false) {
if (key_exists($name, $this->fields)) {
return $this->fields[$name];
}
elseif ($this->isExtended() and $includeExtends) {
$result = $this->extends->getField($name, true);
return $result;
}
else {
throw new Exception("field '$name' does not exists");
}
}
/**
* Getter for array of all fields of model (including inheritated fields)
* @return array
*/
public function getFieldNames() {
$fieldNames = array();
foreach ($this->getFields() as $field) {
$fieldNames[$field->getName()] = $field->getName();
}
if ($this->extends) {
$fieldNames = array_merge($fieldNames, $this->extends->getFieldNames());
}
return $fieldNames;
}
/**
* Getter for model's fields
* @return array
*/
public function getFields() {
return $this->fields;
}
/**
* Getter for foreign keys
* @return array
*/
public function getForeignKeys() {
$keys = array();
foreach ($this->fields as $field) {
if (get_class($field) == 'ForeignKeyField') {
$keys[] = $field;
}
}
return $keys;
}
/**
* Getter for model's hash
* @return string
*/
public function getHash() {
return $this->hash;
}
/**
* Getter for model's indexes
* @return array
*/
public function getIndexes() {
return $this->indexes;
}
/**
* Returns last modification of model
* @return integer
*/
abstract protected function getLastModification();
/**
* Getter for model's name
*/
public function getName() {
return get_class($this);
}
/**
* Getter for primary key field name
* @return string
* @todo remove check for multiple primary keys on table, needed to check elsewhere
*/
public function getPrimaryKey() {
if (is_null($this->primaryKey)) {
$primaryKey = null;
$hits = 0;
foreach ($this->fields as $field) {
if ($field->isPrimaryKey()) {
$primaryKey = $field->getName();
$hits++;
}
}
if ($hits > 1) {
throw new Exception("multiple primary keys on table '$this->getTableName()'");
}
elseif ($hits > 0) {
$this->setPrimaryKey($primaryKey);
return $primaryKey;
}
else {
return false;
}
}
else {
return $this->primaryKey;
}
}
/**
* Getter of all model's properties
*
* Required for loading of serialized object's properties from cache
*/
public function getProperties() {
return get_object_vars($this);
}
/**
* Getter for all tablenames from inheritated models
* @return array
*/
public function getAllTableNames() {
$result = array();
if ($this->isExtended()) {
$result = array_merge($result, $this->getExtend()->getAllTableNames());
}
$result = array_merge($result, array($this->getTableName()));
return $result;
}
/**
* Getter for sql table name
* @return string
*/
public function getTableName() {
if (is_null($this->tableName)) {
$className = get_class($this);
$className[0] = strtolower($className[0]);
$func = create_function('$c', 'return "_" . strtolower($c[1]);');
$this->tableName = preg_replace_callback('/([A-Z])/', $func, $className);
}
return is_null($this->prefix) ? $this->tableName : $this->prefix . $this->tableName;
}
/**
* Checks if model has field with name $name
* @return boolean
*/
public function hasField($name) {
foreach ($this->getFields() as $field) {
if ($field->getRealName() == $name or $field->getName() == $name) {
return true;
}
}
if ($this->extends) {
return $this->extends->hasField($name);
}
return false;
}
/**
* Import (load) model with values
* @param array $values
*/
public function import($values) {
if (!is_array($values)) {
throw new Exception("invalid datatype of import values, array expected");
}
foreach ($values as $path => $value) {
$field = $this->pathLookup($path);
if ($field->getIdent() == PerfORM::ForeignKeyField && !is_object($value)) {
$field->setLazyLoadingKeyValue($value);
$field->enableLazyLoading();
}
else {
$field->getModel()->__set($field->getName(), $value);
}
}
}
/**
* Add (insert) model to database
*
* Triggers NOTICE when no data to add
*
* @return mixed model's primary key value
*/
public function insert() {
$insert = array();
foreach ($this->getFields() as $key => $field) {
$finalColumn = $field->getRealName() . '%' . $field->getType();
if ($field->isPrimaryKey() and $field->getIdent() == PerfORM::AutoField) {
}
elseif (!is_null($value = $field->getDbValue(true))) {
$insert[$finalColumn] = $value;
}
elseif (!$field->isNullable()) {
throw new Exception(get_class($this) . " - field '$key' has no value set or default value but not null");
}
}
if (count($insert) > 0) {
#Debug::barDump($insert, 'insert array');
PerfORMController::queryAndLog('insert into %n', $this->getTableName(), $insert);
$this->setUnmodified();
$insertId = $this->getConnection()->insertId();
$this->fields[$this->getPrimaryKey()]->setValue($insertId);
return $insertId;
}
else {
trigger_error("The model '" . get_class($this) . "' has no data to insert", E_USER_NOTICE);
}
}
/**
* Checks if model is extended
* @return boolean
*/
public function isExtended() {
return isset($this->extends) ? true : false;
}
/**
* Checks if model was frozen
* @return boolean
*/
protected function isFrozen() {
return $this->freeze;
}
/**
* Checks if model and it's fields are modified
* @return boolean
*/
public function isModified() {
return $this->modified;
}
/**
* Determines if model is table
* @return boolean
*/
public function isTable() {
return!$this->view;
}
/**
* Determines if model is view
* @return boolean
*/
public function isView() {
return $this->view;
}
/**
* Load model definition from cache if exists; if not, build model
*/
protected function loadDefinition() {
$cache = PerfORMController::getCache();
$cacheKey = $this->getCacheKey();
if (isset($cache[$cacheKey]) and is_object($cache[$cacheKey]) and get_class($cache[$cacheKey]) == get_class($this)) {
foreach ($cache[$cacheKey]->getProperties() as $property => $value) {
$this->{$property} = $value;
}
}
else {
$this->buildDefinition();
}
}
/**
* Interface to QuerySet's
* @return QuerySet
*/
public function objects() {
return new QuerySet($this);
}
/**
* Finder of reference field mapped with $path
*
* @example pneumatika__dezen__nazov
* @param string $path
* @param string $delimiter
* @result Field
*/
public function pathLookup($path, $delimiter = '__') {
$pointer = null;
$reference = $this;
$fields = explode($delimiter, $path);
$iterator = count($fields);
foreach ($fields as $field) {
$iterator--;
if ($reference->hasField($field) &&
$reference->getField($field, true)->getIdent() == PerfORM::ForeignKeyField) {
$pointer = $reference->getField($field, true);
$reference = $pointer->getReference();
}
elseif ($reference->hasField($field) &&
$iterator === 0) {
$pointer = $reference->getField($field, true);
}
else {
throw new Exception("Invalid element '$field' in path '$path'.");
}
}
return $pointer;
}
/**
* Saving model
*
* When primary key is set, model will be updated otherwise inserted
* @return mixed model's primary key value
*/
public function save() {
if ($this->isView()) {
throw new Exception('Unable to save view.');
}
$pk = $this->getPrimaryKey();
// has primary key set, record exists -> updating
if ($this->fields[$pk]->getValue()) {
if ($this->isExtended()) {
$this->extends->save();
}
return $this->update();
}
// no primary key value, record does not exists -> inserting
else {
if ($this->isExtended()) {
$this->{$pk} = $this->extends->save();
}
return $this->insert();
}
}
/**
* Setter for model alias
* @param string $alias
*/
public function setAlias($alias) {
$this->alias = $alias;
}
public function setLazyLoading() {
$paths = func_get_args();
if (empty($paths)) {
foreach ($this->getForeignKeys() as $field) {
$field->enableLazyLoading();
}
return;
}
foreach ($paths as $path) {
$this->pathLookup($path, '->')->enableLazyLoading();
}
}
/**
* Setter for primary key field name
* @param string $primaryKey
*/
protected function setPrimaryKey($primaryKey) {
$this->primaryKey = $primaryKey;
}
/**
* Definition of model
* @abstract
*/
abstract protected function setup();