Compare parent and child fields' values in array after filtering

trigger to update child record when parent is updated
update parent field from child salesforce apex
how to access parent field from child in apex
access parent from child apex
sobject get parent field
apex reference parent field
how to query child records from parent in salesforce
how to access child records from parent in salesforce

I have the following array of parents and children Stackblitz:

const parents = of(
  [
    { id: 1, type: 'A', children: [{ id: 3, type: 'A' }, { id: 4, type: 'C' }] },
    { id: 2, type: 'B', children: [{ id: 5, type: 'D' }, { id: 6, type: 'B' }] }
  ]);

I need to filter the parent where there is a child with id equal to 6:

{ id: 2, type: 'B', children: [{ id: 5, type: 'D' }, { id: 6, type: 'B' }] }

For that I used RxJs operators:

parents.pipe(
  flatMap(parents => parents),
  map(parent => parent.children.find(child => child.id == 6))
).subscribe(x => console.log(x));

The output is the following child:

{id: 6, type: "B"}

But I need to get an Observable<boolean> which value is true if:

parent.type == child.type (In this case it would be true, e.g., 'B' == 'B')

I have been trying FlatMap, Reduce, Filter, Find, ...

But I am never able to end up with the parent so I can compare parent and child types.

{ id: 2, type: 'B', child: { id: 6, type: 'B' } }

If you replace this: parent.children.find(child => child.id == 6) with parent.find(p => p.children.some(c => c.id === 6)) then instead of receiving {id: 6, type: "B"} you will receiver the parent with all children.

If you want to set only the child that has id 6 you can edit the line map(parent => parent.children.find(child => child.id == 6)) with

 map(parent => {
   parent.child = parent.children.find(c => c.id === 6);
   return parent;
 })

After that instead of receiving {id: 6, type: "B"} you will get the parent with additional property child (parent.child) containing the child that has id 6. And then you can make the check parent.type === parent.child.type. Note that parent.child might be undefined so adding additional check would be necessary.

Comparing Parent fields with all the child records and updating all , I'm not entirely certain I understand the relationships, but let me see if I can point you in the right direction. I'm going to make the assumption that you want to do� The wizzard allows only AND conditions between up to 3 match fields between Parent and Child. parent Id = 12345 Child contestant 1=12345, contestent 2 = 67890 Child contestant 1 = 95124, contestant 2 = 12345


You were on the right track, you just need to map your observable to a boolean, that check whether or not your child type will be equals to the parent type, we can reuse your current map and makes it returns a boolean instead of the child. We do that because we need both the parent and the child at the same time.

parents.pipe(
  flatMap(parents => parents),
  map(parent =>  {
    // we get the child with id 6
    let child = parent.children.find(child => child.id == 6)
    // we check if the child exists ( in the first case it does not )
    // we check if the parent type is equals to the child type.
    return child && parent.type === child.type;
  }),
).subscribe(x => console.log(x) /* true or false */);

I've forked / edited your stackblitz with this fix.

SOQL Relationship Query : Compare Child and Parent field value in , I don't think so. The field expression in the where clause can include only 1 field name and not 2. It must be compared to a native value. Disclaimer: The information provided on DevExpress.com and its affiliated web properties is provided "as is" without warranty of any kind.Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose.


Below code is tested and should work, and if you need to match some id you can do in reduce to add more conditions

import { from } from 'rxjs';
import {mergeMap,first,reduce,filter,last,defaultIfEmpty} from 'rxjs/operators'

const parents = 
  [
    { id: 1, type: 'A', children: [{ id: 3, type: 'A' }, { id: 4, type: 'C' }] },
    { id: 2, type: 'B', children: [{ id: 5, type: 'D' }, { id: 6, type: 'C' }] }
  ];
from(parents).pipe(
    mergeMap(parent=>from(parent.children).pipe(reduce((acc:any,child)=>{
         console.log(parent.type,child.type)
         if(acc) return acc
         return child.type===parent.type
    },false))),
    filter((bool:any)=>bool),
    defaultIfEmpty(false)
   ).subscribe(console.log)

How to compare the value of 2 fields on the child object of a lookup , I can get the values of the parent tax account ids and the field values of new and old levy using SOQL. In the For statement I is wher3e my� Is there a way to do a query to compare fields from linked item to parent item? What I need to do a query finding Items that have been changed after their parent has been changed. In order to do this I want to do a query in which I find the relevant items and display linked items where the state change date < the change date of the parent item.


how to access parent fields on soql where condition ?, I am trying to compare parent name & child name field in soql where item is parent, Item cost is child and have a lookup relationship. Below is� I am trying to compare parent name & child name field in soql where item is parent, Item cost is child and have a lookup relationship. Below is my query :- SELECT Id, Name, KNDY4__Item__c, KNDY4__Item__r.Name FROM


Parent and Child classes having same data member in Java , Comparison of Inheritance in C++ and Java � Output of Java Program | Set 1. Article Tags : Java. Practice Tags : Java. When you create a parent-child relationship, the parent task number is saved in the Parent field in the Project Tasks table. All project management tasks have a parent: either another project task or the project itself. Unlike a dependency, a parent-child relationship is not saved as a record in any table.


Generating a Parent-Child Hierarchy (EE) |, Combining Responses � Response Editing; Creating New Fields Generating a Parent-Child Hierarchy (EE) � Generating a Level-Based Hierarchy (EE) Comparison Widget (EX) � Scorecard Widget (EX) � Question List Widget (EX)� Returns child documents whose joined parent document matches a provided query. You can create parent-child relationships between documents in the same index using a join field mapping. Because it performs a join, the has_parent query is slow compared to other queries. Its performance degrades as the number of matching parent documents increases.