From c9d9281c63ed3394b1b6e92a9c8280f0ab1a3cca Mon Sep 17 00:00:00 2001
From: Dave Mc Nicoll <info@mcnd.ca>
Date: Mon, 30 Oct 2023 19:41:40 +0000
Subject: [PATCH] - Added a new clone() method to Repository() base class

---
 src/Annotation/Property/Field.php | 2 +-
 src/Repository.php                | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/Annotation/Property/Field.php b/src/Annotation/Property/Field.php
index cfbf886..7b8dea0 100644
--- a/src/Annotation/Property/Field.php
+++ b/src/Annotation/Property/Field.php
@@ -8,7 +8,7 @@ class Field implements \Notes\Annotation {
 
     public string $name;
     
-    public int $length;
+    public int|string $length;
 
     public int $precision;
 
diff --git a/src/Repository.php b/src/Repository.php
index 8c8992d..2e30078 100644
--- a/src/Repository.php
+++ b/src/Repository.php
@@ -144,6 +144,15 @@ class Repository
         }
     }
 
+    public function clone(object|array $entity) : bool
+    {
+        foreach(Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField() as $key => $field) {
+            unset($entity->$key);
+        }
+
+        return $this->save($entity);
+    }
+    
     public function save(object|array $entity, ? array $fieldsAndValue = null, bool $replace = false) : bool
     {
         if ( is_array($entity) ) {