开发者

Getting ODBC connection results as ruby object

开发者 https://www.devze.com 2023-03-04 11:13 出处:网络
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'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消