-
Notifications
You must be signed in to change notification settings - Fork 354
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
Inserting objects without ID #62
Comments
Yes, use companions! The documentation should have pointed this out, so let's keep this issue open until I fix the docs. Edit: It's fixed on develop, will release another versions of the docs when the next version comes out. |
Ok, so now I'm. confused in the docs it says to create the setter to use a companion as the parameter but when I call the setter I should use the normal DataClass? Doing so gives type mismatches and I cant seem to construct the companion in the same way as demonstrated in the update section as Value() is not found by dart. |
@NovaLogicDev You should use companions for all inserts or updates. Using the regular data classes will work as well, but only for backwards compatibility. I just realized that the docs use a If you import |
Just to be clear I should Import moor on main.dart/wherever I use the dbo as well? |
Everywhere you use construct a export 'package:moor_flutter/moor_flutter.dart' show Value; in your database dart file, then you don't have to import moor everywhere else. |
Ah that's a neat trick, cool that fixed all the issues. Thanks for the quick response |
Refers to the documentation: https://moor.simonbinder.eu/queries/
I have a question about inserts.
In the documentation
Todo()
is used for creating the object.When I create an object without ID (
autoIncrement()
is used), the IDE (VSCode) will display a warning:The parameter 'id' is required.dart(missing_required_param)
.It seems moor_generator also attaches
@required
to the ID, even though it is usingautoIncrement()
. Although this will not throw an error during runtime. When omitting other columns it will result in a runtime error.Could this be changed to not display the warnings?
Also I noticed in your gist from before that you used a Companion also when inserting.
Should I also use Companion object when inserting? This would probably solve the warning problem mentioned above. Or should it only be used for updates?
Current
pubspec.lock
:Thank you!
The text was updated successfully, but these errors were encountered: