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

Preventing unsetting parent.linkedField from virtual link issue #410

Open
bhunjadi opened this issue Jan 16, 2020 · 0 comments
Open

Preventing unsetting parent.linkedField from virtual link issue #410

bhunjadi opened this issue Jan 16, 2020 · 0 comments

Comments

@bhunjadi
Copy link
Contributor

I have two linked collections:

const parentSchema = new SimpleSchema({
    childId: {
        type: String,
        regEx: SimpleSchema.RegEx.Id,
    },
});

const Parent = new Mongo.Collection('parent');
Parent.attachSchema(parentSchema);
const Child = new Mongo.Collection('child');

Parent.addLinks({
        child: {
            type: 'one',
            collection: Child,
            field: 'childId',
        },
    });
    Child.addLinks({
        parent: {
            collection: Parent,
            inversedBy: 'child',
        },
    });

My issue here is that I don't want grapher to unset childId field in parent when removing child document because SimpleSchema errors with Child ID is required.

What I want is to provide my own handler where I have to do some checks and potentially even change childId to some other child and not remove it and definitely not nullify it.

Therefore,

Child.addLinks({
        parent: {
            collection: Parent,
            inversedBy: 'child',
            autoremove: true,
        },
    });

won't work because I'll be left without a parent.

I think there should be an option to opt out of everything related to autoremoval/unsetting of fields.

Looking into linker.js it looks like there is no opt-out from autoremove on virtual links.

First, we have _initAutoremove which respects the autoremove flag.
Second, we have _handleReferenceRemovalForVirtualLinks which is called for virtual links if autoremove is false (is this even intended behaviour?).

If _handleReferenceRemovalForVirtualLinks being called when autoremove==false is correct behaviour, then we possibly need another parameter.
If it should be only called when autoremove==true, then we have two functions for handling virtual links removal (I'm counting also the one in _initAutoremove) which seems like it is not intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant