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

Constructor if AutoIncrement field is present #2

Open
TnTo opened this issue Aug 9, 2023 · 1 comment
Open

Constructor if AutoIncrement field is present #2

TnTo opened this issue Aug 9, 2023 · 1 comment

Comments

@TnTo
Copy link

TnTo commented Aug 9, 2023

Hi!
The example in the documentation (https://iskyd.github.io/Wasabi.jl/stable/) doesn't compile.

The error shown is

ERROR: MethodError: no method matching User(::String)
Closest candidates are:
User(::Any, ::Any)
User(::Union{Nothing, AutoIncrement}, ::String)

referring to the row user = User("John Doe") because the constructor misses the argument for the autoincrementing id field

@iskyd
Copy link
Owner

iskyd commented Aug 9, 2023

Hi @TnTo , thanks for pointing this out!
I think that we have two options available here:

  • we can simply pass Nothing as the first argument -> user = User("John Doe")
  • we can add a constructor to the user struct
mutable struct User <: Wasabi.Model
    id::Union{Nothing, AutoIncrement}
    name::String
   User(name::String) = new(nothing, name)
end

What do you think?

iskyd pushed a commit that referenced this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants