vivus has quit [Remote host closed the connection]
<FromGitter>
<Hansterdam> I can use some help around the Union types and how to get rid of that. So, I'm retrieving an object from the DB with granite using <Class>.find :id. Then I want to toggle a value on that and save it again. But, since it's of a type <Class> | Nil, I cannot just do that. But how do I get rid of the Nil? If I wrap it in an if statement with .not_nil! or != Nil or <Object>.class == <Class>. Nothing gets rid of the
<FromGitter>
... union and it still throws compile errors. I could of course create two functions and overload them for <Class> and Nil, but if I keep doing that I'm just getting a big bunch of Nil functions that do nothing... Far from ideal. How to solve this?
<FromGitter>
<Hansterdam> Sorry for that !<Class>.nil? does seem to work
_whitelogger has joined #amber
feepbot has quit [Ping timeout: 272 seconds]
feepbot has joined #amber
<FromGitter>
<Blacksmoke16> using Granite @Hansterdam ?
<FromGitter>
<Blacksmoke16> you can use `.find!` to raise on nil so that crystal knows it cannot be nil
<FromGitter>
<robacarp> Just make sure youβre rescuing from the exception elsewhere π¬
<FromGitter>
<Hansterdam> @Blacksmoke16 Ah, thanks! That was what I was looking for :)
<FromGitter>
<Hansterdam> @robacarp π
<FromGitter>
<Blacksmoke16> np, but yea as robacarp said, make sure you handle when an id isnt found
vivus has joined #amber
pracabor is now known as robacarp
hightower6 is now known as hightower2
hightower2 has quit [Changing host]
hightower2 has joined #amber
hightower2 has quit [Remote host closed the connection]
hightower2 has joined #amber
<FromGitter>
<Thellior> @Hansterdam There is also destroy! update! save! methods :)