Я новичок в использовании Laravel Scout и Typesense. Я только что столкнулся с ситуацией, когда пытаюсь обновить связанную коллекцию.
Вот моя модель пользователя
public function toSearchableArray()
{
return array_merge($this->toArray(),[
'id' => (string) $this->id,
'name' => (string) $this->name,
'role_ids' => (array) $this->role_ids,
'created_at' => $this->created_at->timestamp,
]);
}
Моя конфигурация разведчика
User::class => [
'collection-schema' => [
// 'enable_nested_fields' => true,
'fields' => [
['name' => 'id', 'type' => 'string'],
['name' => 'name', 'type' => 'string'],
[
'name' => 'role_ids',
'type' => 'string[]',
'reference' => 'roles_index.id'
],
['name' => 'created_at', 'type' => 'int64']
],
'default_sorting_field' => 'created_at',
],
'search-parameters' => [
'query_by' => 'name'
],
],
У моего почтальона:
/multi_search
[
{
"collection": "users_index",
"q": "*",
"query_by": "name",
"include_fields": "$roles_index(*) as roles"
}
]
Когда у меня есть 1 user.role_ids и я пытаюсь добавить еще один, в typeSense обновятся как role_ids, так и >роли. Но когда я попытаюсь удалить 1 идентификатор из role_ids, элемент объекта в поле roles останется прежним.
Сценарий 1
// upon updating and adding 1 role
role_ids: [1, 2]
roles: [
{
id: 1,
name: "role 1"
},
{
id: 2,
name: "role 2"
}
]
Сценарий 2
// upon updating and removing 1 role
role_ids: [1]
roles: [
{
id: 1,
name: "role 1"
},
{ // this should be removed as well
id: 2,
name: "role 2"
}
]
Подробнее здесь: https://stackoverflow.com/questions/787 ... ollections
Laravel Scout с Typesense удаляет элементы в связанных коллекциях ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение