1602 / 1602/jugglingdb

updateAttributes on jugglingdb-redis breaks index for non-string fields

Abierto
#349 14 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
2k
Forks
238
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Thank you for all your hard work. I ran into an issue with the jugglingdb-redis adapter. I have several fields that are defined such as:

``` javascript
status: { type: Number, default: 1, index: true }
```

When I create an instance of the object with that field it saves fine and I can see in the store that there is an index created. However if I call updateAttributes on the same instance later the index actually disappears. I've debugged this and traced it back to the following code: [redis.js Line291](https://github.com/jugglingdb/redis-adapter/blob/master/lib/redis.js#L291). It compares the value being saved with the previous value and if they are different it adds the new one and removes the old one. The problem is it uses a !== for comparison so even though you could be passing the same value it will be removed if it is a number, or date or anything but a string. All keys and values in `prevData` are strings because they come from the hash that was retrieved with a `hgetall` at line 260. So when you try to do a `findOne` later on `status` it fails because it was removed from the index.

Let me know if this makes sense. I'd love to have this working so that I can use numbers, booleans, etc. and still search on them even after updating the records.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.