faustinoaq changed the topic of #amber to: Welcome to Amber Framework community! | https://amberframework.org | Developer happiness, productivity and bare metal performance | GH: https://github.com/amberframework | Docs: https://docs.amberframework.org | Gitter: https://gitter.im/amberframework/amber | IRC Logger: https://irclog.whitequark.org/amber | Amber::Server.start
<FromGitter> <eliasjpr> @Blacksmoke16 https://github.com/amberframework/granite/issues/361
<FromGitter> <Blacksmoke16> is a PR to fix it when doing `#to_h`
<FromGitter> <eliasjpr> no
<FromGitter> <eliasjpr> I just open a ticket
<FromGitter> <Blacksmoke16> https://github.com/amberframework/granite/pull/359 no i mean i already fixed that part
<FromGitter> <eliasjpr> I need to look into the current implementation to propose a fix
<FromGitter> <Blacksmoke16> however the `#create` or `#new` is going to be a bit more tricky
<FromGitter> <Blacksmoke16> since you cant use `Enum` in a union
<FromGitter> <eliasjpr> yeah
<FromGitter> <eliasjpr> No?
<FromGitter> <Blacksmoke16> nope
<FromGitter> <eliasjpr> You cant use an Enum in a union? WTF!
<FromGitter> <eliasjpr> Is a type no?
<FromGitter> <Blacksmoke16> not like `Enum`
<FromGitter> <Blacksmoke16> but `MyEnum` would work
<FromGitter> <Blacksmoke16> so either we can maybe remove some type restrictions on new/create to allow anything, or define some way to "register" custom types?
<FromGitter> <eliasjpr> I created an enum ⏎ ⏎ ```enum ProductTypes ⏎ Goods ⏎ Service ⏎ end``` [https://gitter.im/amberframework/amber?at=5d803efcd5c523462f96c2c4]
<FromGitter> <Blacksmoke16> yea you could use `ProductTypes` in a union, but not the base `Enum` type
<FromGitter> <Blacksmoke16> i.e. like `alias = String | Int32 | Enum`
<FromGitter> <eliasjpr> got it
<FromGitter> <eliasjpr> We should be able to push the custom type to the `Granite::ModelArgs`
<FromGitter> <eliasjpr> I would expect that each model would have a `ModelArgs` constant that we can add the custom type
<FromGitter> <Blacksmoke16> i have an idea
<FromGitter> <Blacksmoke16> i wonder if we can generate that alias based on types in the model
<FromGitter> <eliasjpr> that should would since the column is a macro
<FromGitter> <Blacksmoke16> sec
<FromGitter> <eliasjpr> Like `alias ModelArgs = Bool | ProductType` in my case?
<FromGitter> <Blacksmoke16> like i did for `#to_h`
<FromGitter> <eliasjpr> just started to look at the PR
<FromGitter> <eliasjpr> Yeah I see what you did
<FromGitter> <eliasjpr> but instead of having the fields inside the method we should be able to create a reusable constant. Wdyt?
<FromGitter> <eliasjpr> `ModelTypes = {{"Hash(String, Union(#{@type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.type.id).splat})).new".id}}`
<FromGitter> <Blacksmoke16> hmm can you use a const as a type restriction like that?
<FromGitter> <eliasjpr> I believe is doable since is a constant (pre compilation), we can also do an alias
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7ks5 nope
<FromGitter> <eliasjpr> https://play.crystal-lang.org/#/r/7ks8 it worked with alias
<FromGitter> <eliasjpr> that will work for me.
<FromGitter> <eliasjpr> And I like having the alias per model definition since it will allow me to create any method that takes that union alias
<FromGitter> <eliasjpr> This works too `MODEL_TYPES = Union(Int32 | String)`
<FromGitter> <Blacksmoke16> cool yea, and looks like you can define an alias per model
<FromGitter> <Blacksmoke16> let me see if i can get this working
<FromGitter> <eliasjpr> This makes me think that `(alias TYPE = Int32 | String) == (MODEL_TYPES = Union(Int32 | String)) `
<FromGitter> <Blacksmoke16> think it has to be `alias`
<FromGitter> <eliasjpr> im fine with that, what ever works :)
<FromGitter> <eliasjpr> I really like the idea of having the `MODEL_TYPES` restricted only to the types defined for that model
<FromGitter> <Blacksmoke16> i dont think i can be done
<FromGitter> <Blacksmoke16> only have access to the ivars within a method
<FromGitter> <Blacksmoke16> :/
<FromGitter> <Blacksmoke16> let me try something else
<FromGitter> <Blacksmoke16> hm
<FromGitter> <eliasjpr> we cannot define a create method like ⏎ ⏎ ```Model#create(args : ModelArgs)``` [https://gitter.im/amberframework/amber?at=5d8044d9c82c2e0d7eea8044]
<FromGitter> <Blacksmoke16> we can, but how would you define the `ModelArgs` type?
<FromGitter> <eliasjpr> within the macro
<FromGitter> <Blacksmoke16> based on ivar types?
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> i have an idea
<FromGitter> <eliasjpr> we keep appending to the constant 😅 :
<FromGitter> <eliasjpr> so each model overwrites the ModelArgs constants from Granite::Base
<FromGitter> <eliasjpr> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5d8045fc05fd3716953b1603]
<FromGitter> <Blacksmoke16> should be doable
<FromGitter> <eliasjpr> yeah, it might take some thinking before approaching
<FromGitter> <Blacksmoke16> indeed
<FromGitter> <Blacksmoke16> well there's a problem
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5d80485853bbf77ee077f4f6]
<FromGitter> <Blacksmoke16> granite supports converting string input to their types
<FromGitter> <Blacksmoke16> holy shit it worked
<FromGitter> <Blacksmoke16> Will have to think more if this would work
<FromGitter> <eliasjpr> :0