1๐
โ
I thought
prefretch_related
does that trick but in DRF.
This will fetch the Component
s for the Vessel
s, but since your serializers do not serialize these components, these will not end up in the result.
You should define the ComponentSerializer
as subserializer for VesselSerializer
, so:
class ComponentSerializer(serializers.ModelSerializer):
class Meta:
model = Component
fields = '__all__'
class VesselSerializer(serializers.ModelSerializer):
vessel_components = ComponentSerializer(many=True) # ๐ subserializer
class Meta:
model = Vessel
fields = '__all__'
Source:stackexchange.com