ActiveRecord joins: integer columns converted to strings

牧云@^-^@ 提交于 2019-12-21 19:26:05

问题


I have a model named Article, which I am joining with TwitterShare as shown below:

articles = Article.joins("LEFT OUTER JOIN twitter_shares ON articles.id = twitter_shares.article_id").where("articles.id = ? or articles.id = ?", 27165, 5632).select("articles.id, twitter_shares.user_id")

When I get the articles back, and examine the Article model returned, it returns the user_id as a string, even though the column type in the twitter_shares table is an integer. Why is this? How can I make ActiveRecord return the integer column as an integer, not a string?


回答1:


Why not just convert the returned user_id with .to_i where you need it as integer?



来源:https://stackoverflow.com/questions/16639344/activerecord-joins-integer-columns-converted-to-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!