-
Notifications
You must be signed in to change notification settings - Fork 17
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
Renaming a model attribute or deleting an attribute and creating a new attribute with the same args of the deleted one #22
Comments
Hi @abrl91, You're right, the API isn't very clear about this. The Subjects can only be nodes that can contain other nodes, such as models which can contain fields or attributes, or fields which can contain attributes. An attribute never becomes the current subject because it doesn't contain anything else. However, I agree that it isn't very satisfying from a user perspective for the builder to make this distinction. It would be nice for the TypeScript system to automatically assign the type of the current subject to These are the kinds of kinks that I want to make sure are worked out of the interface before releasing v1 of the library, and I'm open to suggestions for how it can be improved.
In the meantime, I think this would achieve the effect you're seeking: builder.model(model.name).then<Model>((model) => {
for (const prop of model.properties) {
if (prop.type === 'attribute' && prop.name === ID_ATTRIBUTE_NAME) {
prop.name = UNIQUE_ATTRIBUTE_NAME;
return;
}
}
}); |
@MrLeebo Thank you, it works! |
The issue with the About BTW, we use your library for a very important feature (in Amplication), and I must say that it really helps us and it is very easy to use and understand. |
Yeah, that type definition is too broad. It should be |
I am trying to rename an attribute, but instead, it renames my model:
I tried another way, which is finding the attribute I want to rename, taking its args and creating from it a new attribute, from the type (name) I want and then delete the attribute that I don't want:
In this case, I am getting the following error:
Subject must be a prisma field!
What am I doing wrong? Does this library support what I am trying to do?
The text was updated successfully, but these errors were encountered: