mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Add method addJoinedRecordValues
This commit is contained in:
@ -154,7 +154,7 @@ public class QRecord implements Serializable
|
||||
return (null);
|
||||
}
|
||||
|
||||
Map<String, V> clone = new LinkedHashMap<>();
|
||||
Map<String, V> clone = new LinkedHashMap<>(map.size());
|
||||
for(Map.Entry<String, V> entry : map.entrySet())
|
||||
{
|
||||
Serializable value = entry.getValue();
|
||||
@ -246,6 +246,24 @@ public class QRecord implements Serializable
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
** copy all values from 'joinedRecord' into this record's values map,
|
||||
** prefixing field names with joinTableNam + "."
|
||||
***************************************************************************/
|
||||
public void addJoinedRecordValues(String joinTableName, QRecord joinedRecord)
|
||||
{
|
||||
if(joinedRecord == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(Map.Entry<String, Serializable> entry : joinedRecord.getValues().entrySet())
|
||||
{
|
||||
setValue(joinTableName + "." + entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
@ -291,4 +291,24 @@ class QRecordTest extends BaseTest
|
||||
assertFalse(jsonObject.has("errorsAsString"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testAddJoinedRecordValues()
|
||||
{
|
||||
QRecord order = new QRecord().withValue("id", 1).withValue("shipTo", "St. Louis");
|
||||
order.addJoinedRecordValues("orderInstructions", null);
|
||||
assertEquals(2, order.getValues().size());
|
||||
|
||||
QRecord orderInstructions = new QRecord().withValue("id", 100).withValue("instructions", "Be Careful");
|
||||
order.addJoinedRecordValues("orderInstructions", orderInstructions);
|
||||
|
||||
assertEquals(4, order.getValues().size());
|
||||
assertEquals(100, order.getValue("orderInstructions.id"));
|
||||
assertEquals("Be Careful", order.getValue("orderInstructions.instructions"));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user