-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Can we store a literal object to an entity's field? #262
Comments
A simple proposal: #263 |
Another way is to support: factory({
timelineItemEffectMetadata: {
id: primaryKey(v4),
settings: (initialValue) => Object(initialValue), // note it now gets the initialValue param
},
}) Which gives us extra flexibility. |
Hey, @StanleySathler. Nested objects are supported but you have to describe those objects as well, meaning let Data know which properties you expect them to have and their respective value types. import { nullable } from '@mswjs/data'
const db = factory({
timelineItemEffectMetadata: {
settings: nullable({
intensity: Number
})
}
})
Supporting
|
To give you a little context, I've been rewriting Data from scratch for about a year now (not because it's super complex but simply because I have very little time to dedicate to this library). I've addressed a lot of issues in the new version by accounting for various scenarios from the conception phase. Seeing how active you are with your feedback, would you be interested in joining forced with me and finally shipping that new Data that's going to absolutely blow everybody away? @StanleySathler, let me know! |
Hey @kettanaito 👋 Sorry for the late response. I'm fully active again.
In my case, the problem is that the object doesn't have a known structure. It's a SQL JSON column, which means it can store any valid object.
Sure thing! I mean, we've been adopting mswjs/data in some of our repos at work, so would be fair if I could help somehow. Let me know how we can make this happen. |
So I assume we should drop #263 in favor of this rewrite? |
@StanleySathler, we can still follow through with your proposal. The rewrite I mentioned is not landing any time soon, I've got plenty of work to do in other areas around MSW. Meanwhile, many would benefit from plain Object support in the schemas. I think I left a few comments last time I reviewed your pull request. Let me know what is the state of it, I will do my best to help you ship this feature. |
@StanleySathler @kettanaito Hi all, any updates about this, we really need this feature and we are doing dark magic to make it work but it would be great if the library could handle it! |
Released: v0.16.2 🎉This has been released in v0.16.2! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Great work guys! 👏
One of my fields should represent a JSON column supported by some DBMS. They're able to store any valid JSON object.
My model:
Then:
For some reason
settings
is always an empty object when I retrieve it.The text was updated successfully, but these errors were encountered: