FromGitter has quit [Remote host closed the connection]
FromGitter has joined #amber
_whitelogger has joined #amber
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #amber
<FromGitter>
<andrewc910> Jennifer orm allows you to save and skip validations like `user.save(skip_validation: true)`. Does granite support some sort of save macro/method whilst skipping all model validations?
<FromGitter>
<Blacksmoke16> whats the use case for wanting to skip them?
<FromGitter>
<andrewc910> And how can you detect if something is a new record vs a persisted record?
<FromGitter>
<Blacksmoke16> there's a property on it, that gets set when it gets saved/fetched from the db
<FromGitter>
<Blacksmoke16> iirc `.persisted?`
<FromGitter>
<andrewc910> Ill play around with `#persisted`. Use case for skipping validations. I have trackable module which updates a few items when a user logins in such as `sign_in_count`. Skipping validations is what devise does for rails in this module and there really isn't a need to ensure email is unique on a persisted record.
<FromGitter>
<Blacksmoke16> ah since it was already saved, no need to run validation again?
<FromGitter>
<andrewc910> Yeah, the only validations i have in are ensuring the email is an email, it's unique, password is above 6 chars and if there is a new password, digest it. ⏎ ⏎ None of those are needed when i am updating `sign_in_count` or `current_ip_address`, you know?
<FromGitter>
<Blacksmoke16> would have to be a feature request, logic atm is just `return false unless valid?`
<FromGitter>
<Blacksmoke16> would be pretty easy feature tho, just add optional named arg to `#save`
<FromGitter>
<andrewc910> The discussion in the issue is definitely over my head but it's good study material :) Agree my problem is related to it. ⏎ ⏎ Ill take a look at the implementation. If i understand it, i will make a pull request!
<FromGitter>
<Blacksmoke16> `return false if !skip_validations && !valid?`
<FromGitter>
<Blacksmoke16> or prob could use `unless` i dont remember if it should be `&&` or `||` tho
<FromGitter>
<andrewc910> Why would we return false? Wouldn't that prevent saving
<FromGitter>
<Blacksmoke16> if `skip_validations` is false yea
<FromGitter>
<Blacksmoke16> which would be the default
<FromGitter>
<andrewc910> Oh i think that's my miscommunication then. `#save(skip_validations: true)` should still save, just skip the callbacks hence the `unless skip_validations` on each of the callback lines
<FromGitter>
<Blacksmoke16> sorry to be clear `valid?` is what runs the callbacks
<FromGitter>
<Blacksmoke16> `return false if !skip_validations && !valid?` would only return if `skip_validations` is `false` and `valid?` is `false`
<FromGitter>
<Blacksmoke16> otherwise if you pass true for skip validations, then the expression would return and wouldnt run the validations