aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade')
-rw-r--r--Digitigrade/Model.php4
-rw-r--r--Digitigrade/Model/FetchableModel.php5
2 files changed, 6 insertions, 3 deletions
diff --git a/Digitigrade/Model.php b/Digitigrade/Model.php
index b5c9e99..a065154 100644
--- a/Digitigrade/Model.php
+++ b/Digitigrade/Model.php
@@ -71,6 +71,10 @@ abstract class Model {
} elseif (is_array($value)) {
// arrays ought to be handled separately when saving (different db table)
$discarded = true;
+ } elseif ($value == null && $pName == 'id') {
+ // don't overwrite an existing primary key with null ..
+ // this is kinda janky but it hopefully will work
+ $discarded = true;
}
if (!$discarded)
$result[self::mangleName($pName)] = $value;
diff --git a/Digitigrade/Model/FetchableModel.php b/Digitigrade/Model/FetchableModel.php
index e091a87..bd25d39 100644
--- a/Digitigrade/Model/FetchableModel.php
+++ b/Digitigrade/Model/FetchableModel.php
@@ -15,9 +15,8 @@ abstract class FetchableModel extends Model implements RemoteFetchable {
protected static function fetchFromRemote(string $uri, bool $autoSave): ?static {
// fetch the object
- $data = @file_get_contents($uri, context: stream_context_create(['http' => [
- 'header' => 'Accept: application/json'
- ]]));
+ // janky hack: if this is an Instance then avoid recursively fetching itself
+ $data = @get_remote_object_authenticated($uri, static::class == Instance::class);
if ($data === false)
return null;
$data = json_decode($data);