mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
Merge pull request #91 from meilisearch/add-primary-key-to-fields-map
add primary key to fields_id_map when not present
This commit is contained in:
commit
794fce7bff
@ -516,7 +516,7 @@ fn compute_primary_key_pair(
|
|||||||
) -> anyhow::Result<(FieldId, String)> {
|
) -> anyhow::Result<(FieldId, String)> {
|
||||||
match primary_key {
|
match primary_key {
|
||||||
Some(primary_key) => {
|
Some(primary_key) => {
|
||||||
let id = fields_ids_map.id(primary_key).expect("primary key must be present in the fields id map");
|
let id = fields_ids_map.insert(primary_key).ok_or(anyhow!("Maximum number of fields exceeded"))?;
|
||||||
Ok((id, primary_key.to_string()))
|
Ok((id, primary_key.to_string()))
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@ -572,17 +572,6 @@ mod test {
|
|||||||
use super::compute_primary_key_pair;
|
use super::compute_primary_key_pair;
|
||||||
use super::FieldsIdsMap;
|
use super::FieldsIdsMap;
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[should_panic]
|
|
||||||
fn should_panic_primary_key_not_in_map() {
|
|
||||||
let mut fields_map = FieldsIdsMap::new();
|
|
||||||
let _result = compute_primary_key_pair(
|
|
||||||
Some("toto"),
|
|
||||||
&mut fields_map,
|
|
||||||
None,
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_return_primary_key_if_is_some() {
|
fn should_return_primary_key_if_is_some() {
|
||||||
let mut fields_map = FieldsIdsMap::new();
|
let mut fields_map = FieldsIdsMap::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user