Open vaind opened 4 years ago
@vaind I want to implement relations and have a few questions:
PropertyType.Relation
and execute the example I get following error:
objectbox.c.CoreException: 10501 (SCHEMA) - Has no target entity ID: Property info (my property) (2, Relation)
How can I add a target id to the property?
If you could share some code that might help to understand the context better. But, I'll try anyway... :slightly_smiling_face:
This is an example from an internal test; it's a tree with branches and leaves. A leaf has a parent relation to the branch:
obx_model_entity(model, "DataLeaf", 1, 6348606983323322409);
if (syncEnabled) obx_model_entity_flags(model, OBXEntityFlags_SYNC_ENABLED);
obx_model_property(model, "id", OBXPropertyType_Long, 1, 7352554494005967060);
obx_model_property_flags(model, OBXPropertyFlags_ID);
obx_model_property(model, "parentId", OBXPropertyType_Relation, 2, 6351202743278204154);
obx_model_property_flags(model,
(OBXPropertyFlags) (OBXPropertyFlags_INDEXED | OBXPropertyFlags_INDEX_PARTIAL_SKIP_ZERO));
obx_model_property_relation(model, "DataBranch", 1, 7077739940711775368);
As you can see you need some flags to enable the index for the relation property.
Also, obx_model_property_relation is likely of interest, as it tells to which entity type the relation refers to. Here are the C API docs for it:
/// Refine the definition of the property declared by the most recent obx_model_property() call, declaring it a
/// relation.
/// @param target_entity The name of the entity linked to by the relation
/// @param index_id Must be unique within this version of the model
/// @param index_uid Used to identify relations between versions of the model. Must be globally unique.
OBX_C_API obx_err obx_model_property_relation(OBX_model* model, const char* target_entity, obx_schema_id index_id,
obx_uid index_uid);
Hope that helps in a way. Note that we are a bit busy at the moment, I hope that we can start looking into your PRs in about 2 weeks.
I've created a PR to discuss this further
It would be useful to have support for relations: standalone many-to-many as well as property-based to-one relations, see e.g. Go relations. To implement the minimal, the following needs to be addressed:
obx_box_rel_*
objectbox/c.py