Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customizable STI type serialization. #7541

Closed

Commits on Sep 6, 2012

  1. Added customizable STI type serialization.

    Rails will store the name of a child class in the database
    to use for re-instantiating the record as the correct class later.
    By specifying an `inheritance_serializer` and
    `inheritance_deserializer`, you can customize the stored identifier.
    
        class Foo < ActiveRecord::Base
          self.inheritance_serializer = ->(klass) do
            # Map the class to the appropriate type identifier.
            # Defaults to `klass.name`.
          end
    
          self.inheritance_deserializer = ->(type_before_cast) do
            # Map the type identifier back into the appropriate class.
            # Defaults (approximately) to `type_before_cast.constantize`.
          end
        end
    
    This is primarily useful for working with legacy data models.
    Ian Lesperance & Matt Parker authored and elliterate committed Sep 6, 2012
    Copy the full SHA
    d3bfcba View commit details
    Browse the repository at this point in the history