Find a way to handle possible relation targets
Cubicweb web exposed an easy way to retrieve possible target entities for relations, checking cardinality and RQL constraints. This data was used to fill in dropdown components to let users select the right target.
When using client-side code with the API (eg: react forms), there is no such way to get the same data, and expressing this in RQL is very complex/impossible.
In some client project, we created a new endpoint as shown in this MR: cubicweb/cubes/api!54 (closed)
Ideas:
- Add a new RQL keyword
Any Y WHERE X is User, UNRELATED X friend_with Y
Any Y WHERE X eid 123, UNRELATED(X friend_with Y, Y lives_at "Country")
-
Any Y WHERE X is User, UNRELATED(X friend_with Y, X lives_at "Country")
Example with museums: A museum is in a city (in_city) of more than 1000 inhabitants.
class Museum:
title = String()
in_city = SubjectRelation(constraint="O inhabitants > 1000", cardinality="1*")
Any CITY WHERE M is Museum, M in_city CITY, CITY inhabitants > 1000, NOT EXISTS(M in_city CITY)
Example improved RQL:
Any RELATION_CANDIDATE(Museum, in_city)
Also need to filter target types if a relations has several object types. Need to work with values known before creating (case of composite entities).
class Task:
in_team = SubjectRelation("Team", cardinality="1*")
model = SubjectRelation("Model", constraint="O in_team T, S in_team T", cardinality="1*")
When creating a task from a team (composite), the "in_team" relation is known. We must then filter the possible targets for "model" by the "in_team" relation.
- Generate RQL from client
- Use entity methods