Skip to content

Commit 1e992f9

Browse files
authored
Merge pull request #5 from alejandrogq/add_custom_key_attribute
Add custom key attribute
2 parents e1cea19 + ee17b69 commit 1e992f9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Traits/BelongsToKnowledgeBase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
trait BelongsToKnowledgeBase
1515
{
16+
protected string $knowledgeBaseKeyAttribute = null;
17+
1618
public static function bootBelongsToKnowledgeBase()
1719
{
1820
static::created(queueable(function (Model $model) {
@@ -60,13 +62,15 @@ public function knowledgeInsertItems(): array
6062
$chunk->update(['text' => $text->text]);
6163
}
6264

65+
$key = $this->knowledgeBaseKeyAttribute ? $this->{$this->knowledgeBaseKeyAttribute} : $this->getKey();
66+
6367
$items[] = new KnowledgeInsertItem(
6468
id: $chunk->id,
6569
entity: $text->entity,
6670
text: $text->text,
6771
payload: [
6872
...$this->knowledgeBasePayload(),
69-
'original_record_id' => $this->getKey(),
73+
'original_record_id' => $key,
7074
],
7175
);
7276
}

0 commit comments

Comments
 (0)