Class: Symbol
- Inherits:
-
Object
- Object
- Symbol
- Defined in:
- lib/symbolize.rb
Overview
The Symbol class is extended by method quoted_id which returns a string. The idea behind this is, that symbols are converted to plain strings when being quoted by ActiveRecord::ConnectionAdapters::Quoting#quote. This makes it possible to work with symbolized attibutes in sql conditions. E.g. validates_uniqueness_of could not use :scope with a symbolized attribute, because AR quotes it to YAML:
"... AND status = '--- :active\n'"
Having support for quoted_id in Symbol, makes AR quoting symbols correctly:
"... AND status = 'active'"
NOTE: Normally quoted_id should be implemented as a singleton method
only used on symbols returned by read_and_symbolize_attribute,
but unfortunately this is not possible since Symbol is an immediate
value and therefore does not support singleton methods.
Instance Method Summary collapse
Instance Method Details
#quoted_id ⇒ Object
193 194 195 196 197 |
# File 'lib/symbolize.rb', line 193 def quoted_id # A symbol can contain almost every character (even a backslash or an # apostrophe), so make sure to properly quote the string value here. "'#{ActiveRecord::Base.connection.quote_string(self.to_s)}'" end |