Open mcvmcv opened 2 years ago
@mcvmcv Thanks for reporting this. I'm pretty sure that's how it's supposed to work. Let's see...
1/ the model validator is in the user/app space and it's designed to be modified by the user as needed. 2/ the app outputs a snippet/template as the starting point - which seems to be old and incompatible with the DbId logic - and we should update. 3/ in one of my recent apps I implemented this. Can you try it? If good, we can update the template so we use it:
function is_unique(field::Symbol, m::T, args::Vararg{Any})::ValidationResult where {T<:AbstractModel}
samename = findone(typeof(m); NamedTuple(field => getfield(m, field))... )
samename === nothing || samename.id == m.id ||
return ValidationResult(invalid, :is_unique, "already exists")
ValidationResult(valid)
end
Ah, so I should have named the topic "Can't update models with default is_unique Validator"?
Your new version works like a charm, many thanks!
Describe the bug Consider this model:
Create and save one:
Then try to edit it:
The validator sees the already existing Mymodel with name "foo" in the database, and doesn't let you save the updated one.
Error stacktrace
If any error is thrown, please copy from the REPL and paste it here
To reproduce As above
Expected behavior SearchLight would recognise the object in the DB as the same as the one you are updating, and allow you to update it
Additional context Please include the output of
julia> versioninfo()
andpkg> st
and