I have the following class which is actually view model and I'm trying to initialize it based on the database model like so:
class Document
@id : Int64
@name : String
JSON.mapping(
id: Int64,
name: String,
)
def initialize(db_model)
@id = db_model.id
@name = db_model.name
end
end
Here is the example data model:
class DatabaseModel < ActiveRecord::Model
@@connection_pool_capacity = 25
@@connection_pool_timeout = 0.03
adapter postgres
table_name database_model
primary id : Int
field name : String
end
However I'm getting the following error:
in src/models/document.cr:10: instance variable '@id' of Document must be Int64, not (Int16 | Int32 | Int64 | Int8 | Int::Null | UInt16 | UInt32 | UInt64 | UInt8)
I'd like to do this the most semantically correct way. Whats the best way to infer the correct type in this situation?