- edited description
GetRelationsOf now causes Range exception if related list has no items
We have code that looks for the relationships of a given attribute in our PODO by using the TRTTIExplorer.GetRelationsOf method. I just pulled the latest code from the Spring Marshmallow branch and now it seems that this method fails when the PODO Attribute has no members in it's list.
A range check error occurs.
class function TRttiExplorer.GetRelationsOf(const entity: TObject;
const relationAttributeClass: TAttributeClass): IList<TObject>;
var
rttiType: TRttiType;
field: TRttiField;
prop: TRttiProperty;
begin
Result := TCollections.CreateList<TObject>;
rttiType := fRttiCache.GetType(entity.ClassType);
for field in rttiType.GetFields do
if field.HasCustomAttribute(relationAttributeClass) then
Result.AddRange(GetSubEntityFromMemberDeep(entity, prop)); < - - This line fails with a range error when the GetSubEntityFromMemberDeep returns a List with zero members
for prop in rttiType.GetProperties do
if prop.HasCustomAttribute(relationAttributeClass) then
Result.AddRange(GetSubEntityFromMemberDeep(entity, prop));
end;
This seems to be something new as our code using this method was working before the latest pull. Are we doing something wrong now or is this possibly a bug?
Comments (4)
-
reporter -
reporter By the way. I looked at the prior code and it did the following before calling the AddRange method:
LEntities := GetSubEntityFromMemberDeep(AEntity, LField); if LEntities.Any then Result.AddRange(LEntities);
I have added this check back to the method and now it works fine for us.
-
repo owner - changed milestone to 1.2
- changed component to Base.Collections
-
assigned issue to
It's an issue in the collections.
I have a fix for that and will commit that later this weekend or on monday.
-
repo owner - changed status to resolved
fixed issue
#106→ <<cset b241736155b6>>
- Log in to comment