You can use belongs_to_active_hash in an ActiveRecord model to create an association with an ActiveHash model.
To enable this globally for all ActiveRecord models, extend ActiveRecord::Base with ActiveHash::Associations::ActiveRecordExtensions. Otherwise, extend the specific model.
Example with shortcuts:
By using the :shortcuts option, you can assign the association using a string (e.g., country_name) instead of an ID.
class Person < ActiveRecord::Base
extend ActiveHash::Associations::ActiveRecordExtensions
belongs_to_active_hash :country, :shortcuts => [:name]
end
# Usage:
person = Person.new
person.country_name = "US" # Automatically finds the Country with name "US"
class Person < ActiveRecord::Base
extend ActiveHash::Associations::ActiveRecordExtensions
belongs_to_active_hash :country, :shortcuts => [:name]
end