Reputation: 4612
Let's say we do:
default_scope :select => '*, 1+1 AS woah'
in a model, we can then access woah as a method on the model, but it's a string. How do we typecast this so that it's an integer?
In my real-world example I'm actually selecting an id from a joined table but it's being typed as a string. I need it to be a ruby integer.
Upvotes: 3
Views: 1721
Reputation: 115342
How about using a read-only virtual attribute in your model:
default_scope :select => '*. 1+1 AS raw_woah'
def woah
raw_woah.to_i
end
Upvotes: 6