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

Default values or hooks for relationship properties? #86

Open
exoup opened this issue Dec 27, 2023 · 3 comments
Open

Default values or hooks for relationship properties? #86

exoup opened this issue Dec 27, 2023 · 3 comments
Labels
feature New feature or request

Comments

@exoup
Copy link

exoup commented Dec 27, 2023

I have a User model with a relationships property that looks like this:

Surveys: {
            model: Survey,
            direction: 'out',
            name: 'IS_PARTICIPANT',
            properties: {
                Feedback: {
                    property: 'feedback',
                    schema: {
                        type: 'string'
                    }
                },
                Complete: {
                    property: 'complete',
                    schema: {
                        type: 'boolean'
                    }
                }
            }
        }

Is there a way to give these a default value or a beforeCreate hook?
When I go to create a user node and associate it with a Survey node, I get a Neo4j error about missing feedback and complete parameters.

I've tried adding a default value but it does not work.

I was creating my user node like this:

    const user = User.createOne({
        name: 'John Doe',
        email: 'john.doe@acme.co',
        department: 'Engineering',
        title: 'Software Engineer',
    });
    await user.relateTo({
        alias: 'Surveys',
        where: {
            target: {
                code: "ABC123"
            }
        }
    })
@themetalfleece
Copy link
Owner

Hey there,

I'm afraid you can't provide default values for relationships, only for the node itself.
I'm noting this, it's a useful feature 👍

@themetalfleece themetalfleece added the feature New feature or request label Jan 8, 2024
@marisb11
Copy link

Hi,
sorry, maybe nothing changed :D about default attribute of relationship properties schema.

So, if relationship props are defined by the same Ischema as model props, it just doesn't mean, that { /**Default value */
default?: any;} is implemented for relationships and i cant just use :

properties: {
someProp: {
property: 'someProp',
schema: {
type: 'string'
default: 'me' // by interface ISchema {....default:any;}
}
},
.

it just doesn't work out.

Thanks,

@themetalfleece
Copy link
Owner

@marisb11 Hey there, I'm afraid that nothing has changed 😓 The default property comes from the validation package (called revalidator), which is a bit outdated and not very easy to adjust. So basically, that property is pretty much useless and should be ignored (both for the model and relationships).

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

No branches or pull requests

3 participants