The sample data shows Shauna Barkley as an employee of Hubbard Education Center.
If I perform an advanced search, choose "Display contacts as": "related contacts" and choose "Employee of" as the relationship and then hit search. I get a lot of results, including Shauna (as expected).
However, if I add to the criteria "Complete or Partial Name": "Hubbard" or even "Organization type": "Organization" I get zero results.
I noticed this isssue when upgrading from 5.33 to 5.39, so I can't be sure it's a regression with 5.39 but possibly?
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
I have given this the regression label as this might be a regression. I am not completely sure if it is one. So feel free to remove the regression label if this is not a regression.
I just tested and this isn't a regression (or not recent if it is) - I tried on demo sites for 5.33 & master side by side
In both cases I got zero results for this query
And if I changed to 'Individual' I got the same results as if I didn't filter by contact type.
If I switch to 'employer of' the organization filter works
ie. it seems to be applying the criteria against the contact to be displayed. I have no idea what it should do - I find it very confusing - but it hasn't changed
I thinkthis is the line and commit causing the problem. If we append $qcache['where'] to the passed in $where variable, we get a where statement that overly restricts the results. @jaapjansma - was that something done on purporse or is it possibly a mistake?
The problem seems to come up for additional criteria in certain tables, but there doesn't seem to be a pattern as to which tables.
For example if the additional criteria is address.country = something, then it DOES return employees of orgs that have an address in that country. Or if you restrict the relationship start date then it works. But as above if you do partial name or contact type, or email, it doesn't work.
I don't know if this helps or makes it more confusing but you can think about what PR 20002 was trying to achieve without getting into cases and relationship head-scratching if it's rephrased like this:
Alice has red card and a blue card.
Bob's name is written on the blue card but not the red one.
Now do a search for red cards and display the names written on them.
You wouldn't expect Bob to be in the results.
And this seems to match @jamie what you were saying on the PR: "first, find everyone who matches the criteria (red cards). Second, find everyone with the given relationship to them (is listed on the card)".
Now do a straight replace of the above with cases and what was happening was Bob was showing up:
Alice has a case of type housing and another of type daycare.
Bob is a benefit specialist on the daycare but not the housing.
Now do a search for housing and display the benefit specialists.
You wouldn't expect Bob to be in the results.
So yes maybe PR 20002 isn't the right solution, but the above makes it clearer to me what it was trying to do.
The part of your analogy that I'm struggling with is this line:
Now do a search for housing and display the benefits specialists.
I don't think you are searching for "housing" or even "housing cases". You are searching for contacts with a housing case. Once you have your list of contacts, I think of them as being context free. So, when you then find the benefits specialist for these contacts, you find all the related benefits specialists.
Ideally, I think the "Display related contacts" should work this way.
What's different about the case search compared to all other related contact searches is that there is additional context to the relationship - specifically, the case id.
I wonder if we should expose both case id and case type in the relationships accordian on the advanced search? Then you could achive this search by expanding the relationships accordian, choosing "Benefits Specialist" as the relationship type and "Housing" as the case type (or you could use auto complete to pick one or more specific cases to get all contacts related to the case).