Skip to content
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

MySql::ResultSet#read returned a Int32. A (Int64 | Nil) was expected. (Exception) #177

Closed
Blacksmoke16 opened this issue Apr 7, 2018 · 1 comment

Comments

@Blacksmoke16
Copy link
Contributor

Blacksmoke16 commented Apr 7, 2018

Happens on latest amberframework/granite version

Example table:

items

CREATE TABLE items
(
  id         INT AUTO_INCREMENT   PRIMARY KEY,
  type_id    INT            NOT NULL
  price      DECIMAL(10, 2) NULL,
  type_name  VARCHAR(255)   NULL,
  published  TINYINT(1)     NULL,
  created_at TIMESTAMP      NULL,
  updated_at TIMESTAMP      NULL,
)

item.cr

require "granite_orm/adapter/mysql"
  class Item < Granite::ORM::Base
    adapter mysql
    table_name items
    field type_id : Int32
    field type_name : String
    field price : Float64
    field published : Bool
    timestamps
  end

app.cr

Item.create(type_id: 99, published: true, type_name: "Anshar", price: 99.00)
p Item.find 1

error

I, [2018-04-06 20:37:51 -04:00 #6427]  INFO -- Granite: INSERT INTO `items` (`type_id`, `type_name`, `price`, `published`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?): [99, "Anshar", 99.0, true, "2018-04-07 00:37:51", "2018-04-07 00:37:51"]
I, [2018-04-06 20:37:51 -04:00 #6427]  INFO -- Granite: SELECT `items`.`id`, `items`.`type_id`, `items`.`type_name`, `items`.`price`, `items`.`published`, `items`.`created_at`, `items`.`updated_at` FROM `items` WHERE `id`=? LIMIT 1: 1
MySql::ResultSet#read returned a Int32. A (Int64 | Nil) was expected. (Exception)
  from lib/db/src/db/result_set.cr:0:9 in 'read'
  from src/api2/models/item.cr:4:3 in 'set_attributes'
  from src/api2/models/item.cr:4:3 in 'from_sql'
  from lib/granite_orm/src/granite_orm/querying.cr:84:13 in 'find_by'
  from lib/granite_orm/src/granite_orm/querying.cr:73:12 in 'find'
  from src/api2.cr:29:1 in '__crystal_main'
  from /usr/share/crystal/src/crystal/main.cr:11:3 in '_crystal_main'
  from /usr/share/crystal/src/crystal/main.cr:112:5 in 'main_user_code'
  from /usr/share/crystal/src/crystal/main.cr:101:7 in 'main'
  from /usr/share/crystal/src/crystal/main.cr:135:3 in 'main'
  from __libc_start_main
  from _start
  from ???
@Blacksmoke16 Blacksmoke16 changed the title Primary key not included in fields in querying.cr MySql::ResultSet#read returned a Int32. A (Int64 | Nil) was expected. (Exception) Apr 7, 2018
@Blacksmoke16
Copy link
Contributor Author

NVM, wasn't using BIGINT on id column

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

1 participant