mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 21:50:45 +00:00
Change to fetch the variant record - helps w/ input values being in other types, and, verifies the record exists!
This commit is contained in:
@ -176,7 +176,8 @@ public class MemoryRecordStore
|
|||||||
if(backendVariantsConfig != null)
|
if(backendVariantsConfig != null)
|
||||||
{
|
{
|
||||||
String variantType = backendMetaData.getBackendVariantsConfig().getVariantTypeKey();
|
String variantType = backendMetaData.getBackendVariantsConfig().getVariantTypeKey();
|
||||||
Serializable variantId = BackendVariantsUtil.getVariantId(backendMetaData);
|
QRecord variantRecord = BackendVariantsUtil.getVariantRecord(backendMetaData);
|
||||||
|
Serializable variantId = variantRecord.getValue(QContext.getQInstance().getTable(variantRecord.getTableName()).getPrimaryKeyField());
|
||||||
backendIdentifier = new Variant(variantType, variantId);
|
backendIdentifier = new Variant(variantType, variantId);
|
||||||
}
|
}
|
||||||
return backendIdentifier;
|
return backendIdentifier;
|
||||||
|
@ -247,15 +247,24 @@ class MemoryBackendModuleTest extends BaseTest
|
|||||||
))).getRecords().get(0).getValueInteger("id");
|
))).getRecords().get(0).getValueInteger("id");
|
||||||
assertEquals(1, planetId1);
|
assertEquals(1, planetId1);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// make sure counts return what we expect per-variant //
|
// make sure counts return what we expect per-variant //
|
||||||
////////////////////////////////////////////////////////
|
// also, put the variant ids as strings, just to make sure we're a little type-flexible there //
|
||||||
QContext.getQSession().setBackendVariants(Map.of(TestUtils.TABLE_NAME_MEMORY_VARIANT_OPTIONS, 2));
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
QContext.getQSession().setBackendVariants(Map.of(TestUtils.TABLE_NAME_MEMORY_VARIANT_OPTIONS, "2"));
|
||||||
assertEquals(3, new CountAction().execute(new CountInput(TestUtils.TABLE_NAME_MEMORY_VARIANT_DATA)).getCount());
|
assertEquals(3, new CountAction().execute(new CountInput(TestUtils.TABLE_NAME_MEMORY_VARIANT_DATA)).getCount());
|
||||||
|
|
||||||
QContext.getQSession().setBackendVariants(Map.of(TestUtils.TABLE_NAME_MEMORY_VARIANT_OPTIONS, 1));
|
QContext.getQSession().setBackendVariants(Map.of(TestUtils.TABLE_NAME_MEMORY_VARIANT_OPTIONS, "1"));
|
||||||
assertEquals(1, new CountAction().execute(new CountInput(TestUtils.TABLE_NAME_MEMORY_VARIANT_DATA)).getCount());
|
assertEquals(1, new CountAction().execute(new CountInput(TestUtils.TABLE_NAME_MEMORY_VARIANT_DATA)).getCount());
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
// assert we fail if trying unknown variant //
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
QContext.getQSession().setBackendVariants(Map.of(TestUtils.TABLE_NAME_MEMORY_VARIANT_OPTIONS, 4));
|
||||||
|
assertThatThrownBy(() -> new InsertAction().execute(new InsertInput(TestUtils.TABLE_NAME_MEMORY_VARIANT_DATA).withRecords(List.of(
|
||||||
|
new QRecord().withValue("id", 1).withValue("name", "England")
|
||||||
|
)))).hasMessageContaining("Could not find Backend Variant in table memoryVariantOptions with id '4'");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user