Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relations support #7

Open
vaind opened this issue Sep 9, 2020 · 3 comments
Open

Relations support #7

vaind opened this issue Sep 9, 2020 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@vaind
Copy link
Contributor

vaind commented Sep 9, 2020

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:

  • add property & standalone relation definitions support to the model
  • for standalone relations: add box methods exposing c-api obx_box_rel_*
  • add necessary c-api callbacks to objectbox/c.py
@vaind vaind added enhancement New feature or request help wanted Extra attention is needed labels Sep 9, 2020
@liquidiert
Copy link

@vaind I want to implement relations and have a few questions:

  • when I add a Property with 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?
  • is there an example how the c objectbox library does this? I couldn't find the implementations on github

@greenrobot
Copy link
Member

If you could share some code that might help to understand the context better. But, I'll try anyway... 🙂

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.

@liquidiert
Copy link

I've created a PR to discuss this further

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants