Skip to content

Commit 72c7bac

Browse files
author
Toby Allen
committed
Revert "increase visibility of primaryKey"
This reverts commit f654e92.
1 parent 4b987f0 commit 72c7bac

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/AnyModel.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class AnyModel extends Model
1010
{
1111

1212
public $timestamps = false;
13-
protected $primaryKey; // increase visibility of primaryKey to allow it to be set in options
1413

1514

1615
public static function table($tablename, $options = []){
@@ -26,6 +25,14 @@ public static function table($tablename, $options = []){
2625

2726
return $Model;
2827
}
28+
public function getIDattribute(){
29+
// due to various contortions Model->id will not always be available and it is not possible to set
30+
// primaryKey and have it work so if it is requested and does not exist rather than returning '' (default behaviour)
31+
// raise an error.
32+
if (!isset($this->{$this->primaryKey})){
33+
throw new \Exception('AnyModel::id does not have a value. Please specify actual id field name');
34+
}
2935

36+
}
3037

3138
}

0 commit comments

Comments
 (0)