i am trying to update the parent field with child field but when I try to assign the child's field value to the parent field I keep getting the error "A non-foreign key field cannot be referenced in a path expression: Review_Informations__r "
public class Reviews {
public static void updateReviewRangeOnContact (List <Review_Info__c> reviewList){
Set <Id> contactIds = new Set <Id> ();
if(reviewList != null && reviewList.size()>0){
for (Review_Info__c revi : reviewList){
if (revi.Contact__c != null){
contactIds.add(revi.Contact__c);
}
}
}
List <Contact> ContactList = new List <Contact> ();
ContactList = [SELECT id, Review_rate__c,(SELECT Id,Review_Rating__c FROM Review_Informations__r)
FROM Contact
WHERE ID IN : contactIds];
for (contact con : ContactList){
con.Review_rate__c = con.Review_Informations__r.Review_Rating__c;
}
if (ContactList != null && ContactList.size()>0 )
update ContactList;
}
}