public void testFillReferencingManyRecords() throws TorqueException
{
ForeignKeySchemaData.clearTablesInDatabase();
for (int i = 1; i <= MANY; ++i)
{
OIntegerPk pkObject = new OIntegerPk();
pkObject.setName("oIntegerPk" + i);
pkObject.setIntegerColumn(i);
pkObject.save();
if (i % 10 != 0)
{
NullableOIntegerFk fkObjectA = new NullableOIntegerFk();
fkObjectA.setName("nullableOIntegerFk" + i + "a");
fkObjectA.setOIntegerPk(pkObject);
fkObjectA.save();
NullableOIntegerFk fkObjectB = new NullableOIntegerFk();
fkObjectB.setName("nullableOIntegerFk" + i + "b");
fkObjectB.setOIntegerPk(pkObject);
fkObjectB.save();
}
}
Criteria criteria = new Criteria();
criteria.addAscendingOrderByColumn(OIntegerPkPeer.ID);
List<OIntegerPk> pkObjectList = OIntegerPkPeer.doSelect(criteria);
assertEquals(MANY, pkObjectList.size());
// check referencing lists are not initialized
for (OIntegerPk oIntegerPk : pkObjectList)
{
assertFalse(oIntegerPk.isNullableOIntegerFksInitialized());
}
List<NullableOIntegerFk> nullableOIntegerFkList
= OIntegerPkPeer.fillNullableOIntegerFks(pkObjectList);
assertEquals(2 * (MANY - (MANY / 10)), nullableOIntegerFkList.size());
int i = 1;
for (OIntegerPk pkObject : pkObjectList)
{
if (i % 10 != 0)
{
assertEquals(2,
pkObject.getNullableOIntegerFks().size());
assertTrue(
pkObject.getNullableOIntegerFks().get(0).getName()
.startsWith("nullableOIntegerFk" + i));
assertTrue(
pkObject.getNullableOIntegerFks().get(1).getName()
.startsWith("nullableOIntegerFk" + i));
}
else
{
assertEquals(0,
pkObject.getNullableOIntegerFks().size());
}
++i;
}
}