ActiveRecord concatenates: entire columns converted to rows

I have a model called Article with which I am joining 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 go back to the articles and examine the returned article model, it returns user_id as a string, even if the column type in twitter_shares is an integer. Why is this? How to get ActiveRecord to return an integer column as an integer, not a row?

+4
source share
1 answer

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

0
source

Source: https://habr.com/ru/post/1481662/


All Articles