Getting ODBC connection results as ruby object
I've had to add an ODBC connection to a remote mysql server into my app.
This is the first time I've done something like this.
I was expecting the results to return as a ruby object, just like the rest of the ActiveRecord requests.
However, I'm beginning to think that maybe ODBC isn't handled the same way through the ruby-odbc gem.
When I output a debug statement on my models which connect through a standard connection, I get the standard
--- !ruby/object:ModelName
attributes:
etc.etc.
but when I output a debug statement on the model connected through the ODBC, i get
[#<ModelName modelID: 1, name: "name" etc. etc. ]
Is there any way for me to get ODBC connections working like the rest of my models?
UPDATE
To clarify, I am hoping to开发者_运维百科 get the data as an object so I can get the data like
<%= @something.name %>
With the way I'm getting the data back now, I can't refer to it as an object.
It looks like it's returning an array of objects, instead of just one. If you only want a single object, just add .first
to the result.
精彩评论