We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have a belongs_to with a foreign_key called obj_id in a model. The foreign key is set to an INT but when I do:
belongs_to
foreign_key
obj_id
INT
Model.find(26)
It returns:
#<Model:0x10f064d80 @_current_callback=nil @error=[], @new_record=false, @destroyed=false, @id=26, @obj_id=nil created_at=nil, updated_at=nil>
created at and updated at are also set in the database.
The model:
class Model < Granite::Base connection pg table models belongs_to user : User, foreign_key: obj_id : Int32? timestamps end
The text was updated successfully, but these errors were encountered:
The issue seems to be connected to connection setting. When I removed it in the model so it use default it seems to work.
connection
Very strange but I think I got it working now.
Sorry, something went wrong.
I haven't been able to recreate this issue using version 0.23.2 of Granite and both sqlite or pg adapters - @confact is this still an issue for you?
I've added the script I used to try to reproduce this in case you think I'm missing something.
require "pg" Granite::Connections << Granite::Adapter::Pg.new(name: "test", url: "postgresql://localhost:5432/granite-tmp") require "granite" require "granite/adapter/pg" class User < Granite::Base connection test table users column id : Int32, primary: true column foo : String end class Model < Granite::Base connection test table models column id : Int32, primary: true belongs_to user : User, foreign_key: obj_id : Int32 timestamps end User.migrator.drop_and_create Model.migrator.drop_and_create user = User.create(foo: "bar") model = Model.create(obj_id: user.id) puts Model.find!(model.id).to_h # => {"id" => 1, "obj_id" => 1, "created_at" => 2023-10-28 10:18:40.0 UTC, "updated_at" => 2023-10-28 10:18:40.0 UTC}
No branches or pull requests
I have a
belongs_to
with aforeign_key
calledobj_id
in a model. The foreign key is set to anINT
but when I do:It returns:
#<Model:0x10f064d80 @_current_callback=nil @error=[], @new_record=false, @destroyed=false, @id=26, @obj_id=nil created_at=nil, updated_at=nil>
created at and updated at are also set in the database.
The model:
The text was updated successfully, but these errors were encountered: