Skip to content

Feature: Relationship fetching & filtering #4

@ShishKabab

Description

@ShishKabab

Motivation: When fetching stuff from storage, we often want to fetch related objects. By doing this in one call, we do not only gain convenience, but give some backends the chance to optimize fetching, for example by generating JOINs in SQL backends.

Design considerations:

  • When fetching an object, we want control over which child and parent objects are also fetched
  • When want to be able to filter fetched relationships (give me all customers of this company with an age over 21)
  • We want to be able to filter objects by their children (give me all customers with an active e-mail)

Example:

storageManager.registry.registerCollections({
    user: {
        version: new Date(2018, 11, 11),
        fields: {
            displayName: { type: 'string' },
            age: { type: 'number' },
        },
        indices: [],
    },
    singleEmail: {
        fields: {
            address: { type: 'string' },
            isActive: { type: 'string' },
        },
        relationships: [
            { singleChildOf: 'user' }
        ]
    },
    multiEmail: {
        fields: {
            address: { type: 'string' },
            isActive: { type: 'string' },
        },
        relationships: [
            { childOf: 'user' }
        ]
    },
})

storageManager.collection('user').findObjects({}, {relationships: ['singleEmail']})
storageManager.collection('user').findObjects({}, {relationships: {'multiEmail.active': true}})
storageManager.collection('user').findObjects({'singleEmail.active': true}, {relationships: ['singleEmail']})
# Do we allow filtering objects by childOf (one-to-many) relationships?
# Do we allow filtering objects by connects (many-to-many) relationships?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions