getRelationList<T> method
Retrieves a list relation typed as T.
Returns an empty list if the relation hasn't been loaded. Returns the cached list if loaded (even if it's an empty list).
Example:
final posts = author.getRelationList<Post>('posts');
Implementation
List<T> getRelationList<T>(String name) {
final relations = _relationValues[this];
if (relations == null || !relations.containsKey(name)) {
return const [];
}
final value = relations[name];
if (value == null) {
return const [];
}
if (value is List<T>) {
return value;
}
if (value is Iterable<T>) {
final list = List<T>.unmodifiable(value);
relations[name] = list;
return list;
}
if (value is Iterable) {
final list = List<T>.unmodifiable(value.cast<T>());
relations[name] = list;
return list;
}
return const [];
}