ActiveRecord的加入:整数列转换为字符串 [英] ActiveRecord joins: integer columns converted to strings

查看:114
本文介绍了ActiveRecord的加入:整数列转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个型号命名文章,我与Twitter分享加入,如下所示:

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")

当我得到的物品回来,并检查返回的文章模型,它返回USER_ID作为一个字符串,即使在twitter_shares表中的列类型是一个整数。为什么是这样?我怎样才能让ActiveRecord的返回整列作为一个整数,而不是字符串?

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?

推荐答案

为什么不直接转换与 .to_i 在你需要它作为整数返回user_ID的?

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

这篇关于ActiveRecord的加入:整数列转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆