[11.x] Create missing Typesense collections using the indexable name

Merged
XU
15d ago
+104-1

If a model uses a different index for writing than for searching (by overriding indexableAs(), as added in #836), writing to Typesense fails when that index doesn't exist yet.

For example, with searchableAs() returning posts and indexableAs() returning posts_v2, importing the model fails with Collection not found.

The cause is in getOrCreateCollectionFromModel(). It checks whether posts_v2 exists, but when it doesn't, it creates the collection using searchableAs(), so posts gets created (or reused) instead. The documents are then sent to posts_v2, which still doesn't exist.

This PR creates the collection with the same name it checked for. If a schema sets its own name, nothing changes.