Skip to content

Refetching links and link props on save #844

@vpetrovykh

Description

@vpetrovykh

Here's the motivation for why links and link props need re-fetching on save.

Consider this schema:

module default {
    type User {
        multi link friends: default::User {
            property nickname: std::str {
                default := 'gang';
            };
        };
        required property name: std::str {
            constraint std::exclusive;
        };
    };
};

It is perfectly reasonable to write the following code:

a = default.User(name='Alice')
b = default.User(name='Billie', friends=[a])
db.save(b)

This should result in both objects a and b to be saved (because they are linked). Also, we explicitly added a to b.friends, and that was very much the point of what was being saved. So it would be surprising if after save we would unset friends. If we're fetching friends, we should also fetch and reload its link props (especially since in this case there's a default value there).

Similarly, it would be odd if after saving either the links became unset or the link props became unset or invalid while the rest of the object gets updated/reloaded. The behaviour should be consistent regardless of whether save creates or modifies an object.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions