-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
The knex adapter's defaultTo doesn't provide default values to hooks #1459
Comments
You may have missed the point here.. this is entirely intended. The There's no way to expose these values to the Keystone hooks that are run before the insert is performed -- the values simply don't exist yet. These values will be available after though (in There are cases where you could substitute the |
The I guess to put it another way; Are there use cases for My main motivation here is to move away from adapter-specific functionality where there's equivalent things available at a higher level within KS. |
Yeah, these options looks similar from the outside but they lend themselves to very different solutions. There are two main points of differences I think -- where the value/function is evaluated and the effect
Evaluating things at the DB level also (usually) gives you a single source of truth. This is usually important for things like incrementing values and serials but can also effect things like the For me though, the most important difference is the resulting schema itself. Keystone defines the DB schema for it's lists but we can't assume Keystone is the only thing interacting with the database. Being able to trust the integrity of your data is incredibly valuable. To do this we need to be able to put rules and constraints around values enforced by the DB itself. Being able to assume, for example, that a record that's inserted (by Keystone or some other method) will always have a primary key, isn't something we want to give up. There's simply no way to ensure this with TL;DR: these options are anything but "equivalent" :) |
It looks like you haven't had a response in over 3 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contributions. :) |
@timleslie you change the hooks function to get all the things... was this covered? |
@MadeByMike @jesstelford : Hi guys, are there any updates on this? As per @molomby comment below:
do we still consider this as a bug? |
The behaviour described is as intended and necessary/inherent in the way the functionality works, so not a bug, I'd say. It is confusing there are multiple ways of defaulting things though -- the two methods discussed above but also in hooks, potentially in the interface, etc. It's possible we should make this clearer. Better docs? Clearer names for the config options? If there is a problem, I think those are the questions we should be asking. |
It looks like there hasn't been any activity here in over 6 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contribution. :) |
Keystone 5 has officially moved into active maintenance mode as we push towards the next major new version Keystone Next, you can find out more information about this transition here. In an effort to sustain the project going forward, we're cleaning up and closing old issues such as this one. If you feel this issue is still relevant for Keystone Next, please let us know. |
For example:
Will always throw an error on create or update because the default isn't set until after the hooks are run.
On the other hand, using a defaultValue doesn't suffer from this issue:
Which will not throw, because the
resolvedData
will have the defaultcreatedAt
date.The
defaultTo
option should most likely be removed from the Knex adapter.The text was updated successfully, but these errors were encountered: