Hi All–
I’m hoping some of the criteria builder foo masters can help me out a bit. Let’s say I have these entities–Car, Part, Color.
Car has many Parts -> one-to-many from Car to Parts
Parts have a Color -> many to one from Parts to Colors
What I’m wanting to do is to retrieve a distinct array of Cars that have green parts (any kind), or perhaps an array of Cars that have white and blue parts. I don’t really care about the parts, just the existence of at least one part for the specified color(s). So in other words, if Car A has 15 red parts, I just want to get back the one Car A.
When I drill down via createAlias to the ColorID, the appropriate results are returned; however, it is the complete joined set (e.g., one “row” for part which matched the color), rather than simply the cars whose parts match the criteria.
Here’s an example of what I’ve tried:
var c = newCriteria();
c.createAlias( “Parts”, “p”).createAlias( “p.Colors”, “c” ).isIn( “c.ColorID”, theArrayOfColorIDs );
I’ve tried a number of other approaches, but each has given me the same result.
Can anyone suggest tweaks (or rewrites) to help me to get to what I need? I appreciate any help that anyone can offer.
Thanks!!