-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Empty values can't be coerced #273
Comments
@SleeplessByte Thanks for reporting this. We'll start reworking Lotus::Model low level mechanisms next week. So we'll take in account this problem. For the time being, you can avoid to hit this problem, by validating your data. |
I actually unset empty values before I pass them to the repository, because the |
@SleeplessByte I'm confused. 😢 You should invoke methods on the repository, only if you're sure they are valid. This is a framework design. In pseudo code: if my_data_is_valid?
MyRepository.create(my_entity_instance)
end As opposite of other libraries like ActiveRecord, where the control happens inside the repository role: MyModel.create(my_data) # check data inside. Do you have some code to share with us? It would help to understand better your use case 😄 Thanks! |
@jodosha Sorry about the confusion. Adding validations to the |
Woops. The bug is still there off course for no validations. |
Which version do you used before, and which one after the upgrade? |
I have not encountered the error since yesterday. |
@SleeplessByte Thank you. I suspect this could be related to hanami/validations#82 /cc @hlegius |
@SleeplessByte if I got you correctly, you're trying to persist About blank values, since hanami/validations#82, you can have blank param's keys for both If you still experiencing some unexpected behaviour on this, please, paste here some of your implementation. I'd be glad to help you! |
@jodosha It was, that's why switching to edge resolved it. @hlegius I was and I was not. I realised quickly that I had to do Right now the flow is something along the lines of: params do
param :foo do
param :bar, baz: :validation
...
end
end
def call( params )
...
if params.valid?
@my_model = MyModel.new( params[ :foo ] )
@my_model = MyModelRepository.create( @my_model ) or raise SomeException
...
end
...
end And this works. I had one problem using Long story short (\cc @jodosha ): Personally, I don't think it is clear enough that
|
When a form is submitted and the value is empty (but present as key because it was in the form).
Coercing
The text was updated successfully, but these errors were encountered: