Check whether a getter is an attribute or an association

Updated . Posted . Visible to the public.

Sometimes you might want to know if an attribute is an associated object or a simple string, integer etc. You can use the reflect_on_association Show archive.org snapshot method for that.

if Person.reflect_on_association(:address)
  Person.address.attributes # do something
else
  Person.address # do something else
end
Dominik Schöler
Last edit
Keywords
belongs_to, has_many
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2011-03-08 16:11)